[R] nice way to find or not a value (problem with numeric(0))
Ptit_Bleu
ptit_bleu at yahoo.fr
Wed Mar 4 09:11:06 CET 2009
Hello,
I have a data.frame called spec containing data about samples. But I don't
have these data for all my samples.
So if I have data (that is code of the sample is in spec$Code), I would like
to assign data1 to the variable m.
If I don't have this data, I would like to assign 1 to m.
I tried this :
m<-spec$data1[spec$Code==code]*(code %in%specmodules$Code) + 1*(!code %in%
specmodules$Code)
It works when I have the data but if it is not the case I get numeric(0)
instead of 1.
I finally use the following command. It works but I'm sure there is a more
elegant way.
if (code %in%spec$Code) m<-spec$data1[spec$Code==code] else m<-1
Is there a way to avoid an if-test ?
Thanks for your help,
Have a good day,
Ptit Bleu.
--
View this message in context: http://www.nabble.com/nice-way-to-find-or-not-a-value-%28problem-with-numeric%280%29%29-tp22325406p22325406.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list