if ive got an incomplete data set thats got thousands of rows and 80 columns with random missing fields...like this say... 3 b 3 4 1 1 x 2 ? how do i turn it into.... 3 b 3 4 missing 1 1 x 2 ...i.e., i want to insert the word "missing" into the fields that are empty? -- View this message in context: http://old.nabble.com/enter-%22missing%22-into-missing-fields-tp26203288p26203288.html Sent from the R help mailing list archive at Nabble.com.
?NA ?read.table (note the "na.strings" argument) You would have to handle character fields/columns (which would by default be converted to factors)specially to convert blanks to missing within R. Bert Gunter Genentech Nonclinical Biostatistics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of frenchcr Sent: Wednesday, November 04, 2009 11:40 AM To: r-help at r-project.org Subject: [R] enter "missing" into missing fields if ive got an incomplete data set thats got thousands of rows and 80 columns with random missing fields...like this say... 3 b 3 4 1 1 x 2 ? how do i turn it into.... 3 b 3 4 missing 1 1 x 2 ...i.e., i want to insert the word "missing" into the fields that are empty? -- View this message in context: http://old.nabble.com/enter-%22missing%22-into-missing-fields-tp26203288p262 03288.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.
On 11/05/2009 06:40 AM, frenchcr wrote:> if ive got an incomplete data set thats got thousands of rows and 80 columns > with random missing fields...like this say... > > 3 b 3 > 4 1 > 1 x 2 > > ? how do i turn it into.... > > 3 b 3 > 4 missing 1 > 1 x 2 > > ...i.e., i want to insert the word "missing" into the fields that are empty? >Hi frenchcr, It is easy to replace fields, but you have to know whether they are blank (as in a character field with nothing in it), NULL (nothing there) or NA (data Not Available). x[nchar(x)==0]<-"missing" x[is.null(x)]<-"missing" x[is.na(x)]<-"missing" will handle those three respectively. However, your example looks like you have whitespace in the "empty" fields. If that is so, you may have to work out what is in the field and then match it with something like: x[x == " "]<-"missing" I am very glad that you didn't want to insert "This space intentionally left blank" as in those pages in books that might have delighted ancient Greek philosophers but merely annoy the logical reader. Jim