affiliatessoli.blogg.se

Rstudio ifelse
Rstudio ifelse









rstudio ifelse

I put in some extra print statements to make it easy to compare the data frames before and after the processing. For that, you can use the mutate_all function from the dplyr package. It looks from your for loop code that you want to modify all of the columns in each data frame. You need to define one or more conditions you would like to meet to run some code, and otherwise, run other code. I will offer a much less general but simpler version. I see that has given an elegant general solution. # loop over scorenames applying our function repeatedly To generalise the approach I offer you something like this structure library(rlang) # for sym() to evaluate chars as symbolsįrame_raw condition_cutoff, !!sym(score_to_split), NA) When I do this, the result is that it just reported ALL the scores into the score_youngs column, without respecting the condition I put! What is my mistake? Ifelse(frame$age <= 16.0, frame$score_youngs <- frame$score, NA)

rstudio ifelse

Here is the code I have made: frame$score_youngs <- NA I have already created an empty column score_youngs full of NAs, and if the participants are younger than 16, I would like to report their scores from a previous column to the newly created column score_youngs.

rstudio ifelse

#Rstudio ifelse how to

I first would like to report the measured scores of the youngest participants to a new column entitled "score_youngs", and then do the same thing with the oldest participants (basically separate the measured scores of the youngs and the oldest, while keeping the original score column). How to apply the ifelse function of the dplyr package in the R programming language. I have a dataframe with a certain number of participants, and a column with their age, as well as several other columns with some scores I have measured.











Rstudio ifelse