[R] Help with replacement of certain values in dataset with SAS code equivalent
Erik Iverson
eriki at ccbr.umn.edu
Mon Apr 26 19:54:02 CEST 2010
> What I want to do is to be able to select certain FTIStandKey's and change
> values in the dataset. For example, I would like to select by
> FTIStandKey=="NAH6253-003", and change the entries for CoverType="
> XSOP-9999-C " and change the V_SpGrp=="T", and also change V_Origin=="T". I
> only want to change the record for the one FTIStandKey. All the other
> records need to remain the exact same. I have spent a good bit of time
> trying to figure this out but with no success. Any help would be greatly
> appreciated.
Do not know if the following will work, and it is not tested since you
don't give a reproducible example, see ?dput and the Posting Guide for
this list. There are several ways of doing what you want, some of which
are possibly more transparent than this:
mydata[mydata$FTIStandKey == "NAH6253-003",
c("CoverType", "V_SpGrp", "V_Origin")] <-
list(" XSOP-9999-C ", "T", "T")
This relies on the fact that if your variables are factors, that they
include the replacement levels already (including the fact that you have
spaces on either side of the string for CoverType... You might also see
?ifelse for another method of dealing with stuff like this.
More information about the R-help
mailing list