r

How to filter rows based on the previous row and keep previous row using dplyr?

无人久伴 提交于 2021-02-15 07:50:40
问题 I am trying to subset rows of a data set using a condition that's based on the previous row, whilst keeping the previous row in the subsetted data. This is essentially the same as the question here, but I am looking for a dplyr approach: Select specific rows based on previous row value (in the same column) I have taken the dplyr approach applied in the comments to that answer, but I am unable to figure out the last step of retaining the previous row. I can get the rows that support the

R: Switching Between Graphs

不羁的心 提交于 2021-02-15 07:42:54
问题 I am using the R programming language. I am trying to follow the tutorial here on "switching between graphs" : https://plotly.com/r/dropdowns/ (first example). First, I generated some data in R: library(plotly) library(MASS) x <- sample( LETTERS[1:4], 1000, replace=TRUE, prob=c(0.25, 0.25, 0.25, 0.25) ) y <- rnorm(1000,10,10) z <- rnorm(1000,5,5) df <- data.frame(x,y, z) df$x = as.factor(df$x) colnames(df) <- c("x", "y", "z") I tried to modify the code from this tutorial to make the final

R - cut function with custom labels?

a 夏天 提交于 2021-02-15 07:35:25
问题 Example: > x <- c(1e6,2e6,500e3,10e6,233e3,50e3) > cut(x,c(0,250e3,500e3,1e6,2.5e6,99e6),dig.lab=10) [1] (500000,1000000] (1000000,2500000] (250000,500000] (2500000,99000000] (0,250000] [6] (0,250000] Levels: (0,250000] (250000,500000] (500000,1000000] (1000000,2500000] (2500000,99000000] Is there a way I can use the cut function with custom labels? I would like it to show labels such as: (0,250k],(250k,500k],(500k,1m],(1m,2.5m],(2.5m,inf] Is there a way to do this? 回答1: As @user20650 said,

ggplot2 issue: graph text shown with weird unicode blocks

主宰稳场 提交于 2021-02-15 07:16:45
问题 I have got the following problem: When I plot anything with ggplot2 like this # Libraries library(ggplot2) # create data xValue <- 1:10 yValue <- cumsum(rnorm(10)) data <- data.frame(xValue,yValue) # Plot ggplot(data, aes(x=xValue, y=yValue)) + geom_line() The resulting graph looks like this where the text is shown in weir unicode blocks: ggplot2 graph with text issue These unicode blocks look like boxes with four numbers starting with two 0s like: # Example block ---- |00| |2C| ---- I

ggplot2 issue: graph text shown with weird unicode blocks

 ̄綄美尐妖づ 提交于 2021-02-15 07:15:12
问题 I have got the following problem: When I plot anything with ggplot2 like this # Libraries library(ggplot2) # create data xValue <- 1:10 yValue <- cumsum(rnorm(10)) data <- data.frame(xValue,yValue) # Plot ggplot(data, aes(x=xValue, y=yValue)) + geom_line() The resulting graph looks like this where the text is shown in weir unicode blocks: ggplot2 graph with text issue These unicode blocks look like boxes with four numbers starting with two 0s like: # Example block ---- |00| |2C| ---- I

No standard output received inside foreach loop [duplicate]

独自空忆成欢 提交于 2021-02-15 07:11:51
问题 This question already has answers here : How can I print when using %dopar% (6 answers) Closed 3 years ago . I'm using doParallel to do fairly long parallel processing with foreach . Rather than most examples I see, where a computationally-intensive but input-light code is fed into the loop, I'm using foreach to coordinate the simultaneous processing of a number of large, independent datasets. So inside the loop, I'm using metadata to read in a file from disk, operate on it, and write back

No standard output received inside foreach loop [duplicate]

半城伤御伤魂 提交于 2021-02-15 07:10:31
问题 This question already has answers here : How can I print when using %dopar% (6 answers) Closed 3 years ago . I'm using doParallel to do fairly long parallel processing with foreach . Rather than most examples I see, where a computationally-intensive but input-light code is fed into the loop, I'm using foreach to coordinate the simultaneous processing of a number of large, independent datasets. So inside the loop, I'm using metadata to read in a file from disk, operate on it, and write back

Warnings when running an lmer in R

﹥>﹥吖頭↗ 提交于 2021-02-15 06:49:55
问题 I am trying to run a linear mixed-effects model in R using the function lmer, but I keep getting the same warning messages. I am attempting to analyze the effects of graded air density, thorax temperature (main effects), and hive selection (random effect) on flight metabolic rate in honey bees. There looks like there is a strongly significant effect of this "aerial treadmill" I've developed, I just need to figure out the stats to back up my claims. Attached is my code: #Loading my dataset

Warnings when running an lmer in R

你。 提交于 2021-02-15 06:49:07
问题 I am trying to run a linear mixed-effects model in R using the function lmer, but I keep getting the same warning messages. I am attempting to analyze the effects of graded air density, thorax temperature (main effects), and hive selection (random effect) on flight metabolic rate in honey bees. There looks like there is a strongly significant effect of this "aerial treadmill" I've developed, I just need to figure out the stats to back up my claims. Attached is my code: #Loading my dataset

Create new variable by multiple conditions via mutate case_when

允我心安 提交于 2021-02-15 06:21:08
问题 Hi want to create a new variable/column (WHRcat) by 2 variables (WHR and sexe) under a certain condition wth dyplr, mutate and case_when. Data: WHR sexe WHRcat (new variable) 1.5 1 2.8 2 0.2 2 0.3 1 1.1 1 My code: test<- test%>% mutate(WHRcat = case_when((WHR >= 1.02 & sexe = 1) ~ 1, (WHR < 1.02 & sexe = 1) ~ 2, (WHR >= 0.85 & sexe = 2) ~ 3, (WHR < 0.85 & sexe = 2) ~ 4, TRUE ~ 0)) Though doesnt work. Error: > test<- test%>% mutate(WHRcat = case_when((WHR >= 1.02 & sexe = 1) ~ 1, + (WHR < 1.02