The easiest is often to fix this when importing your data. Most functions for importing data has some argument to specify which values should be interpreted as NA, for example:
read.csv and the like: na.strings
readr::read_csv and the like: na
readxl::read_excel and the like: na
Just set this argument to "", " " or to any value that is not interpreted as NA by R.
If this is not an option for you, you can replace the blank values with NA using:
发布评论
评论(2)
您可以使用以下代码将所有空值替换为
NA
:You could replace all the empty values with
NA
by using the following code:最简单的方法通常是在导入数据时解决此问题。大多数用于导入数据的函数都有一些参数来指定哪些值应解释为
NA
,例如:read.csv
等:na.strings
readr::read_csv
等:na
readxl::read_excel
等:na
只需设置
""
的这个参数," "
或 R 不解释为NA
的任何值。如果这不适合您,您可以使用 NA 替换空白值:
数据
The easiest is often to fix this when importing your data. Most functions for importing data has some argument to specify which values should be interpreted as
NA
, for example:read.csv
and the like:na.strings
readr::read_csv
and the like:na
readxl::read_excel
and the like:na
Just set this argument to
""
," "
or to any value that is not interpreted asNA
by R.If this is not an option for you, you can replace the blank values with NA using:
Data