Using this df:
DF = data.frame(m=rep(1:2,2), y=rep(1998:1999,each=2), A=c(2:5), B=c(4,NA,6,7))
> DF
m y A B
1 1 1998 2 4
2 2 1998 3 NA
3 1 1999 4 6
4 2 1999 5 7
How could I replace a single cell using as coordinates this values:
m = 2 ; y = 1999 ; col = 'A' ; val = 72
Following those values I want to replace 5 with 72.
Edit. As testing all the answers I realized my question is very basic and don't represent my problem. I tried to do it without for loops but failed and eventually used it.
So, I want to replace values within the DF
data frame but using this other data frame:
repl = data.frame(m=c(2,1), y=c(1999,1998), col=c('A','B'), val=c(72,100))
> repl
m y col val
1 2 1999 A 72
2 1 1998 B 100
This means that each row of the repl
data frame is a value to replace in DF
.
I've been trying to use Psidom answer mutate(A = replace(A, m == 2 & y == 1999, 72)
for each row but wonder if can be done without loops or without using column names.
Thank you.