When using read.table in r, r gives some blank cells NA values and leaves others blank. Is something wrong?

StackOverflow https://stackoverflow.com/questions/16195040

  •  11-04-2022
  •  | 
  •  

I am reading a csv file into r (with the blank.lines.skip=T option). It has some character,numeric, and factor variables. When r reads the file in, some cells are given NA's while others are left blank. It appears that only columns with all numeric data are given NA while columns with other types of data are left blank. My data set is too large to check all of this by hand. I have many columns and rows in my data, and am not sure why some cells are getting the NA and others aren't, unless it is by design. Any advice is appreciated. Cheers.

有帮助吗?

解决方案

When expecting a number in a cell and not finding it read's would assign a type-appropriate NA to that cell. If instead expecting a string (or a factor), an empty cell is a valid entry , thus no NA's.

So NA's will only be in numeric class columns, but not in character or factor class ones.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top