Hi,all a quick question A larger file include many"." (stands for missing value) for variable, say, x. after read in the file and assign it another name such as : x1<-data$x but x1 is always a facotor but not numerical. so How can I get a numeric vector from the read in data frame. how can I replace those "." with "NA" to perform analysis. thank you very much best regards
Dear Yong Wang, When you read the data with read.table, specify the argument na.strings=".". See ?read.table for details. I hope that this helps, John> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Yong Wang > Sent: Saturday, May 29, 2004 8:25 PM > To: r-help at stat.math.ethz.ch > Subject: [R] how to remove "." or replace it with NA? > > Hi,all > a quick question > A larger file include many"." (stands for missing > value) for variable, say, x. after > read in the file and assign it another name such as : > > x1<-data$x > > but x1 is always a facotor but not numerical. > > so How can I get a numeric vector from the read in data frame. > how can I replace those "." with "NA" to perform analysis. > > thank you very much > best regards > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
If the data file is in text format, is large with a lot of "."s, use sed. It's MUCH faster than any other tool for this sort of thing. -----Original Message----- From: Yong Wang [mailto:wang at galton.uchicago.edu] Sent: Sunday, May 30, 2004 05:25 To: r-help at stat.math.ethz.ch Subject: [R] how to remove "." or replace it with NA? Hi,all a quick question A larger file include many"." (stands for missing value) for variable, say, x. after read in the file and assign it another name such as : x1<-data$x but x1 is always a facotor but not numerical. so How can I get a numeric vector from the read in data frame. how can I replace those "." with "NA" to perform analysis. thank you very much best regards ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html