在R中加载数据集时出错 [英] Error while loading dataset in R

查看:1247
本文介绍了在R中加载数据集时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载从这个链接下载的数据集:
https://docs.google.com/spreadsheet/ccc?key=0AkY2lFgS9uiDdDdxazdLMnUwalpyMjc0UlY1U2p4cnc#gid=0



我将其下载到我的C驱动器在这个位置C:/ CDA驱动器作为popular.tsv



我正在尝试读入数据帧。我使用源和负载,我在这两个中都有错误。

 > present = source(C://CDA//popular.tsv)
源错误(C://CDA//popular.tsv):
C://CDA//popular.tsv:1:9:意外符号
1:性别等级
^
>现在=加载(C://CDA//popular.tsv)
错误:坏的恢复文件魔术数字(文件可能已损坏) - 无数据加载
另外:警告消息:
文件'popular.tsv'有魔术数字'gende'
使用2之前的保存版本已被弃用

> present = read.table(C:// CDA //popular.tsv)
扫描错误(文件,什么,nmax,sep,dec,quote,skip,nlines,na.strings,
第23行没有11个元素

请帮忙!
谢谢

解决方案

您正在使用错误的函数来读取数据。



加载是用于使用R保存的对象保存的数据文件(通常以.Rdata或.rda结尾的文件)。 source 通常用于读取文件或连接包含R脚本。



您应该尝试 read.table 和family。由于这是一个标签分隔文件,您可以使用:

  r ead.delim(C://CDA//popular.tsv)
## ^^与`read.table(...,header = TRUE,sep =\t)相同)
## see?read.table了解更多详情


Hi I am trying to load a dataset that I downloaded from this link: 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

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"). source is generally used to read files or connections containing R scripts.

You should try read.table and 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

这篇关于在R中加载数据集时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆