简体   繁体   English

在R中读取csv文件

[英]Reading csv file in R

I read my csv file in R using 我使用R读取了我的csv文件

data <- read.csv("data.csv",header = FALSE)

What I get is 我得到的是

name place    phone #
sam  london   5343234
     NA       NA
jim  USA      4325235
john USA      NA
     NA       NA

How to remove the row with NA.These NA appear because I had a excel file in which there were spaces and I saved that file as csv.I want to generalize this code so the spaces could appear anywhere.So how to clean this up? 如何用NA删除行。出现这些NA是因为我有一个excel文件,其中有空格,并且将该文件另存为csv。我想对此代码进行泛化,以便空格可以出现在任何地方,那么如何清理呢?

由于NA似乎是空行,因此您可以尝试:

data <- read.csv("data.csv", header=FALSE, blank.lines.skip=TRUE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM