[R] Modifying a data.frame

Bapst Beat Beat.Bapst at braunvieh.ch
Sun Oct 3 10:58:02 CEST 2010


 Hello list members

I have a problem with modifying a data.frame.
As an example given is a data.frame called ex :


ex<-data.frame(id=c(1,2,3,4,5,6),obs=c(14,9,20,36,55,47),eff=c("A","A","B","C","C","C"))


After that I would like to modify the object ex with the following short script:


for (i in ex) {

if(ex[i,3]=="A"|| ex[i,3]=="C"){

ex[i,4]<--9999

}

else {

ex[i,4]<-10

}

}

This script is creating an error message:

Fehler in if (ex[i, 3] == "A" || ex[i, 3] == "C") { :
  Fehlender Wert, wo TRUE/FALSE nötig ist


Why this script  doesn't  work properly?

Thanks a lot for your hints

Beat



More information about the R-help mailing list