I'd like to replace a value in a data frame with an NA, but can't figure out how. For example, say you have a<-c(1,2,3,4) b<-c(5,6,7,8) data<-data.frame(a,b) Now, how would you set the third row of the second column ( data [[3,2]] ) to NA? I have tried all types of permutations with is.na, including is.na<- data[[3,2]], which does not work. Thanks
Henrique Dallazuanna
2007-Feb-09 16:35 UTC
[R] Replace individual values in a data frame with NA
data[3,2]<-NA On 09/02/07, Jason Horn <jhorn@bu.edu> wrote:> > I'd like to replace a value in a data frame with an NA, but can't > figure out how. > > For example, say you have > > a<-c(1,2,3,4) > b<-c(5,6,7,8) > data<-data.frame(a,b) > > Now, how would you set the third row of the second column ( data > [[3,2]] ) to NA? > > I have tried all types of permutations with is.na, including is.na<- > data[[3,2]], which does not work. > > Thanks > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-ParanĂ¡ Brasil [[alternative HTML version deleted]]
Michael Kubovy
2007-Feb-09 16:39 UTC
[R] Replace individual values in a data frame with NA
On Feb 9, 2007, at 11:10 AM, Jason Horn wrote:> I'd like to replace a value in a data frame with an NA, but can't > figure out how. > > For example, say you have > > a<-c(1,2,3,4) > b<-c(5,6,7,8) > data<-data.frame(a,b) > > Now, how would you set the third row of the second column ( data > [[3,2]] ) to NA?a<-c(1,2,3,4) b<-c(5,6,7,8) data<-data.frame(a,b) data[3, 2] <- NA ?Extract _____________________________ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400 Charlottesville, VA 22904-4400 Parcels: Room 102 Gilmer Hall McCormick Road Charlottesville, VA 22903 Office: B011 +1-434-982-4729 Lab: B019 +1-434-982-4751 Fax: +1-434-982-4766 WWW: http://www.people.virginia.edu/~mk9y/