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

发布于 2024-10-17 11:58:05 字数 621 浏览 1 评论 0原文

我的教授给我发送了一个 .rdata 文件,并希望我对内容进行一些分析。虽然我对 R 很熟悉,但我从未将我的工作保存在 .rdata 文件中,因此从未使用过它们。

当我尝试加载该文件时,它看起来正在工作:

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

但我似乎无法获取数据:

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

我知道 .rdata 文件中有数据(它有 13 MB,里面肯定有很多数据)我做错了什么吗?我不知所措。

编辑:

我应该注意,我也尝试过不使用引号:

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

并重命名:

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

My professor has sent me an .rdata file and wants me to do some analysis on the contents. Although I'm decent with R, I've never saved my work in .rdata files, and consequently haven't ever worked with them.

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? 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人练习一个人 2024-10-24 11:58:05

对于不以字母或 开头的对象,您将会遇到很多问题。和一封信(如中所述R 简介)。

使用反引号访问此对象(help("`") 的“名称和标识符”部分解释了其工作原理)并将该对象分配给一个新的、语法上有效命名的对象。

Data <- `25383-0001-Data`

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).

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.

Data <- `25383-0001-Data`
情愿 2024-10-24 11:58:05

也许这与名称和反引号工作中不寻常地使用破折号有关:

names(`25383-0001-Data`)

编辑:

更多参考(因为 Joshua 已经完美回答了主要问题),您还可以从 ls() 重新分配一个对象 (Wilduck 在问题中尝试过的)使用 get()。如果名称的对象包含非常奇怪的字符,这可能很有用:

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

这当然要求 ls()foo 的索引为 [1]< /code>,但是查找所需对象的索引并不太难。

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(). 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文