[R] data frame question

Bill.Venables at csiro.au Bill.Venables at csiro.au
Fri Feb 15 07:38:29 CET 2008


 
... or in one step

df <- transform(df, 
		col1 = ifelse(col1 > 3, NA, col1))

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of K. Elo
Sent: Friday, 15 February 2008 4:29 PM
To: r-help at r-project.org
Subject: Re: [R] data frame question

Hi,

joseph wrote (15.2.2008):
> Thanks. I have another question:
> In the following data frame df, I want to replace all values in col1
> that are higher than 3 with NA. df= data.frame(col1=c(1:5, NA),col2=
> c(2,NA,4:7))

My suggestion:

x<-df$col1; x[ x>3 ]<-NA; df$col1<-x; rm(x)

-Kimmo

______________________________________________
R-help at r-project.org 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