[R] substitute variable

Benilton Carvalho bcarvalh at jhsph.edu
Mon Mar 26 18:35:44 CEST 2007


say your data frame is called "tmp"

tmp$PRODUCTS[tmp$PRODUCTS > 70] <- NA

b

On Mar 26, 2007, at 12:31 PM, Sergio Della Franca wrote:

> Dear R-Helpers,
>
> I want to substitute the contents of a variable under some contitions.
>
> I.e., I have this data set:
>
> YEAR   PRODUCTS
> 1          80
> 2          90
> 3          50
> 4          60
> 5          30
>
> I want to perform this condition:
> if products> 70 then products=NA else products=products.
>
> I'd like to achive the seguent result:
>
>  YEAR   PRODUCTS
> 1          NA
> 2          NA
> 3          50
> 4          60
> 5          30
> How can i develop this?
>
>
> Thank you in advance.
>
>
> Sergio Della Franca
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list