vendredi 30 avril 2021

Change multiple values with ifelse in tidyverse

I hav a dataset with 20.000 Observations and 5 Variables. Now I want to change in some specific observations only one variable. I know that I can do this for every row like this:

test_data <- test_data%>%
  mutate(change_variable=ifelse(n=="1000","changevalue",changevariable))

My problem is now that I need to change 500 Obersvations like this. Is there any possibility to automate this process instead of writing a code of 500 lines? It is every time the same variable to get changed and I have the right value for this variable in a dataframe connected to the right "n" value.

I Hope someone of you can help me with this.

Kind Regards, Tom

Aucun commentaire:

Enregistrer un commentaire