[R] substitute variable
Benilton Carvalho
bcarvalh at jhsph.edu
Mon Mar 26 18:55:02 CEST 2007
condition1 | condition2 (or)
condition1 & condition2 (and)
tmp$PRODUCTS[tmp$PRODUCTS > 70 | tmp$PRODUCTS < 20] <- NA
b
On Mar 26, 2007, at 12:47 PM, Sergio Della Franca wrote:
> Ok, this run correctly.
>
> Now i want to perform much more conditions, i.e.:
>
> tmp$PRODUCTS[tmp$PRODUCTS > 70] <- NA
>
> and
>
> tmp$PRODUCTS[tmp$PRODUCTS < 20] <- NA.
>
> How can i perform this double condition in the same code?
>
>
> 2007/3/26, Benilton Carvalho <bcarvalh at jhsph.edu>: 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