Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何读取NA值?_R_Csv - Fatal编程技术网

R 如何读取NA值?

R 如何读取NA值?,r,csv,R,Csv,文件t.csv: a ; b ; c ; d 1 ; 2 ; NA; 4 5 ; NA; 6 ; 7 我读了文件t.csv > t <- read.table("t.csv",header = T, sep = ";") 我得到了什么 > str(t) 'data.frame': 2 obs. of 4 variables: $ a: num 1 5 $ b: Factor w/ 2 levels " 2 "," NA": 1 2 $ c: Factor

文件t.csv:

a ; b ; c ; d
1 ; 2 ; NA; 4
5 ; NA; 6 ; 7 
我读了文件t.csv

> t <-  read.table("t.csv",header = T, sep = ";")
我得到了什么

> str(t)
'data.frame':   2 obs. of  4 variables:
 $ a: num  1 5
 $ b: Factor w/ 2 levels " 2 "," NA": 1 2
 $ c: Factor w/ 2 levels " 6 "," NA": 2 1
 $ d: num  4 7
我犯了什么错误?

试试这个:

read.csv("t.csv", sep=";", stringsAsFactors=FALSE, na.strings = " NA")
试试这个:

read.csv("t.csv", sep=";", stringsAsFactors=FALSE, na.strings = " NA")

您可以在
read.表中尝试
strip.white=TRUE

dat <- read.table('t.csv', header=TRUE, sep=';', strip.white=TRUE)
str(dat)
# 'data.frame': 2 obs. of  4 variables:
#$ a: int  1 5
#$ b: int  2 NA
#$ c: int  NA 6
#$ d: int  4 7

您可以在
read.表中尝试
strip.white=TRUE

dat <- read.table('t.csv', header=TRUE, sep=';', strip.white=TRUE)
str(dat)
# 'data.frame': 2 obs. of  4 variables:
#$ a: int  1 5
#$ b: int  2 NA
#$ c: int  NA 6
#$ d: int  4 7