Dear R-users, My script imports a dataset from a csv file, in which missing values are represented by ".". This importation is done into a dataframe using the read.table function with na.strings = "." Then I want to replace the NAs in the first column of the dataframe by "Missing data". I am using the following code to do so :
mydata<-data.frame(read.table(myFile,sep=",",header=TRUE,na.strings=".")) # myFile is the full path of the source file mydata[,1][is.na(mydata[,1])]<-"Missing value" This code works perfectly fine if this first column contains only missing values, i.e. ".". As soon as it contains multiple levels and missing values, things start to get wrong. I get the following error message and the replacement is not done. Warning message: invalid factor level, NAs generated in: `[<-.factor`(`*tmp*`, is.na(mydata[, 1]), value = "Missing value") Is there an error in my code or is that a bug (I doubt about it) ? Thanks in advance. ______________________________________________ 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.