简体   繁体   English

在R中加载数据集时出错

[英]Error while loading dataset in R

Hi I am trying to load a dataset that I downloaded from this link: https://docs.google.com/spreadsheet/ccc?key=0AkY2lFgS9uiDdDdxazdLMnUwalpyMjc0UlY1U2p4cnc#gid=0 嗨,我正在尝试加载从此链接下载的数据集: https : //docs.google.com/spreadsheet/ccc?key=0AkY2lFgS9uiDdDdxazdLMnUwalpyMjc0UlY1U2p4cnc#gid=0

I downloaded it into my C drive in this location C:/CDA drive as popular.tsv 我将它以Popular.tsv的形式下载到C:/ CDA驱动器的C驱动器中

I am trying to read it into a dataframe. 我正在尝试将其读入数据框。 I use both source and load and I get an error in both of them. 我同时使用源代码和负载,但在两者中都出现错误。

>present=source("C://CDA//popular.tsv")
Error in source("C://CDA//popular.tsv") : 
  C://CDA//popular.tsv:1:9: unexpected symbol
1: gender  grade
       ^
> present=load("C://CDA//popular.tsv")
Error: bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘popular.tsv’ has magic number 'gende'
  Use of save versions prior to 2 is deprecated 

>present=read.table("C://CDA//popular.tsv")
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 23 did not have 11 elements

Please help! 请帮忙! Thanks 谢谢

You are using the wrong functions to read the data in. 您使用了错误的函数来读取数据。

load is for data files which have been saved using R's saved objects (usually files ending with ".Rdata" or ".rda"). load是针对使用R的保存对象保存的数据文件(通常以“ .Rdata”或“ .rda”结尾的文件)。 source is generally used to read files or connections containing R scripts. source通常用于读取包含R脚本的文件或连接。

You should try read.table and family. 您应该尝试使用read.table和family。 Since this is a tab separated file, you can use: 由于这是一个制表符分隔的文件,因此可以使用:

read.delim("C://CDA//popular.tsv") 
## ^^ is the same as `read.table(..., header = TRUE, sep = "\t")
## see ?read.table for more details

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

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