Vote count:
0
I have the below df
var1 var2 freq1 freq2
1 a b 5 10
2 b a 10 5
3 b d 10 10
created from the following code
help <- data.frame(var1 = c("a", "b", "b"), var2 = c("b", "a", "b"), freq1 = c(5, 10, 10), freq2 = c(10, 5, 10))
my intention is to create an ifelse statement where I am able to (1) replace all freq1 values to 0 when var1 equals a, and (2) replace all freq2 values to 0 when var2 equals a. I do not want to change the value if var1 or var2 is not a.
Is the ifelse command not the best way to solve this problem? I started doing each one manually using help$freq1[help$var1 == "a"] <- 0 however, this will take a bit of time as I have multiple variables and a large dataset. Any assistance would be great.
Many thanks.
asked 32 secs ago
Multiple ifelse statement
Aucun commentaire:
Enregistrer un commentaire