if_else(sub2_value=="Alcohol",sub2_day1,NA)),day2_alc=if_else(sub1_value=="Alcohol",sub1_day2,if_else(sub2_value=="Alcohol",sub2_day2,NA)),day3_alc=if_else(sub1_value=="Alcohol",sub1_day3,if_else(sub2_value=="Alcohol",sub2_day3,NA)))...
Not the answer you're looking for? Browse other questions tagged r dplyr orask your own question. R LanguageCollectiveJoin the discussion This question is in a collective:a subcommunity defined by tags with relevant content and experts.
In this blog post, we will explore how to subset a data frame using three different methods: base R’s subset() function, dplyr’s filter() function, and the data.table package. Examples Using Base R’s subset() Function Base R provides a handy function called subset() that allows...
If you want to differentiate male and female patients with their heights(in centimeter), you can perform exploratory analysis first.library(webr) library(ggplot2) library(dplyr) library(tidyr) theme_set(theme_bw()) data(radial,package="moonBook") radial %>% group_by(sex) %>% numSummary...
create_group = function(df,a){ if(missing(a)) a = cumsum(df$weight)%/%100 b = !ave(df$color,a,FUN=seq_along)%%6 d = ave(df$weight,a+b,FUN=cumsum)>100 a = a+b+d if (any(b|d)) create_group(df,a) else cbind(df,group = a+1) } create_group(df) color weight ...
Issue described (with solutions) here but I feel like this would be an excellent feature, contingent on it not being too nightmarish to program. Currently summarise_at/summarise_if/summarize_at/summarize_if can only be used once, on a si...
Today we’ll see what happens when you have not one, but two variables in your model. We will also continue to use some old and new dplyr calls, as well as another parameter for our ggplot2 figure. I’ll be taking for granted some of the set-up steps from Lesson 1, so if you ...
I am trying to use R'sdplyrpackage to create multiple new columns for each year in my dataset that is the sum of the columns corresponding to each year's end of quarter figures (Mar, Jun, Sep, Dec). The only way I have been able to figure out how to do this "effici...
With dplyr: df %>% mutate(DE=ifelse(B < 0.05 & C > 0, "UP", ifelse(B < 0.05 & C <0,"Down","Notsig"))) Or using case_when: df %>% mutate(DE=case_when(B < 0.05 & C>0 ~ "UP", B<0.05 & C<0 ~ "Down", TRUE ~ "Notsig")) Result: A B C DE 1 G1 0.04...
Pressing backspace in an R Markdown document sometimes deletes 2 lines. I've restarted R Studio and my computer. This issue has been reported in the R Markdown repo rstudio/rmarkdown#1031. > sessionInfo() R version 3.5.1 (2018-07-02) Pla...