I have a data frame like below:
field1 field2 field3
x 1 2
y 3 4
x na na
My goal is to replace all the values in field2 to A and field3 to B when field1 ='x'. I wrote two lines to do this and want to see if there is a way to do this in one line.
df$field2[df$field1=='x'] <- 'A'
df$field3[df$field1=='x'] <- 'B'
Thanks!