Allan Kamau wrote: > I am looking for a way to transform select observations based on a value > based criteria. > Why - Am learning r and would like to perform regression analysis of given > variables of the babies dataset (part of UsingR) for example babies$wt1, the > data in the variables does contain values which should be interpreted as > unknown, some variables have 999 for unknown and some have 99 for the same, > since lm() expects not available data to be marked using NA. > I would like to use a solution that does not employ loops (I think it may not > be the ideal way) > > I am looking at using apply() and supply the name of my function responsible > for transformation, but am unable to know now to reference the element of the > vector/list being currently processed by apply() so I may do in place > substitution (if value is 99 or 999) of the value with NA.
Does this do what you want? babies$wt1 <- with(babies, replace(wt1, wt1 == 999, NA)) ?replace > ____________________________________________________________________________________ > Pinpoint customers who are looking for what you sell. > > ______________________________________________ > R-help@stat.math.ethz.ch 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. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 ______________________________________________ R-help@stat.math.ethz.ch 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.