简体   繁体   English

加载其他人的.rdata文件,无法访问数据

[英]Loading someone else's .rdata file, can't access the data

My professor has sent me an .rdata file and wants me to do some analysis on the contents. 我的教授给我发了一个.rdata文件,希望我对内容做一些分析。 Although I'm decent with R, I've never saved my work in .rdata files, and consequently haven't ever worked with them. 虽然我对R很体面,但我从未在.rdata文件中保存我的工作,因此从未使用过它们。

When I try to load the file, it looks like it's working: 当我尝试加载文件时,它看起来像是在工作:

> load('/home/swansone/Desktop/anes.rdata')
> ls()
[1] "25383-0001-Data"

But I can't seem to get at the data: 但我似乎无法得到数据:

> names("25383-0001-Data")
NULL

I know that there is data in the .rdata file (it's 13 MB, there's definitely a lot in there) Am I doing something wrong? 我知道.rdata文件中有数据(它是13 MB,肯定有很多)我做错了吗? I'm at a loss. 我不知所措。

Edit: 编辑:

I should note, I've also tried not using quotes: 我应该注意,我也尝试过不使用引号:

> names(25383-0001-Data)
Error: object "Data" not found

And renaming: 并重命名:

> ls()[1] <- 'nes'
Error in ls()[1] <- "nes" : invalid (NULL) left side of assignment

You're going to run into a lot of issues with an object that doesn't begin with a letter or . 对于一个不以字母或字母开头的对象,你会遇到很多问题。 and a letter (as mentioned in An Introduction to R ). 和一封信(如R简介中所述 )。

Use backticks to access this object (the "Names and Identifiers" section of help("`") explains why this works) and assign the object to a new, syntactically validly named object. 使用反引号访问此对象( help("`")的“名称和标识符”部分解释了为什么这样做)并将对象分配给一个新的,语法上有效命名的对象。

Data <- `25383-0001-Data`

Maybe it has to do with the unusual use of dashes in the name and backquotes work: 也许它与名称和反引号工作中不寻常使用破折号有关:

names(`25383-0001-Data`)

Edit: 编辑:

More for reference (since Joshua already answered the main question perfectly), you can also reassign an object from ls() (what Wilduck tried in the question) using get() . 更多供参考(因为Joshua已经完全回答了主要问题),你也可以使用get()ls() (Wilduck在问题中尝试过ls()重新分配一个对象。 This might be useful if the object of the name contains very weird characters: 如果名称的对象包含非常奇怪的字符,这可能很有用:

foo <- 1:5
bar <- get(ls()[1])
bar
[1] 1 2 3 4 5

This of course requires the index of foo in ls() to be [1] , but looking up the index of the required object is not too hard. 这当然要求ls()foo索引为[1] ,但查找所需对象的索引并不太难。

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

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