Hi all,

My current project brought forth the snippet below, which modifies in each
row of a data frame a certain field depending on another field in the same
row. Dealing with data of some 30000 entries this works, but is horribly
slow. Can anyone show this newbie how to do this properly (faster ;0)?

for (i in 1:nrow(dataframe)){
  if (any(grep('^yes$',dataframe[i,][['Field1']]))){
    dataframe[i,]['Field1'] <- dataframe[i,]['Field2']
  } else {
    dataframe[i,]['Field1'] <- NA
  }
}

Thanks for your insights, Joh

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to