In this data frame:
Item <- c("A","B","A","A","A","A","A","B")
Trial <- c("Fam","Fam","Test","Test","Test","Test","Test","Test")
Condition <-c("apple","cherry","Trash","Trash","Trash","Trash","Trash","Trash")
ID <- c(rep("01",8))
df <- data.frame(cbind(Item,Trial,Condition,ID))
I would like to replace the value "Trash" df$conditionwith df$Trial == "Test". The new value df$conditionshould be a copy df$conditionin df$Trial == "Fam"based on Fam and test tests in df$Item.
So my final data frame should look like this:
Item Trial Condition ID
1 A Fam apple 01
2 B Fam cherry 01
3 A Test apple 01
4 A Test apple 01
5 A Test apple 01
6 A Test apple 01
7 A Test apple 01
8 B Test cherry 01
Ultimately, I would like to do this for a unique identifier in my original data frame. Therefore, I assume that I will have to apply the function to ddplyor later.
Laura source
share