So I have a a dataframe,df: df = data.frame(c("",1,1),c(1,"",1),c(1,1,""))
I want to loop through the dataframe and replace the values in the first and second column, if they are empty, with the value in the third column if it has a value in it:
n = nrow(df)
for(i in 1:n)df[i,] <-{
if(df[i,1] == "" & df[i,2] == "" & df[i,3] != ""){
df[i,1] = df[i,3]
df[i,2] = df[i,3]
}
}
However, I get the following error:
error in x[[jj]][iseq] <- vjj : replacement has length zero. I've been trying for quite some time, but can't figure our what I'm doing wrong. Any help would be much appreciated.