I am having trouble importing data correctly into r from a txt file with missing values. When I import, the column of numeric values with the missing value (have tried it both as "."
and "Na"
) is read as a factor variable. The import code I use is:
dat2 <- read.table(file.choose(), header = T)
Looking at the structure of the data, I see for the column of interest:
adultreg : Factor w/ 19 levels "1.85","101.75",..: 11 15 15 1 13 6 17 9 16 3
After converting the factor to the numeric variable (dat2$adultreg<-as.numeric(dat2$adultreg)
, I ask r to output the data just so I can see what it is, it is not at all the data from the text file anymore.