rm(a) > load("desktop/Data.-6ren">
gpt4 book ai didi

r - 将文件加载到 R

转载 作者:行者123 更新时间:2023-12-04 11:39:09 26 4
gpt4 key购买 nike

我第一次使用 R 我试图保存数据并再次加载它,我使用这个

> a <- 1:10
> save(a, file = "desktop/Data.Rdata")
> rm(a)
> load("desktop/Data.Rdata")

警告:

 cannot open compressed file 'desktop/Data.Rdata', probable reason 'No such file or directory'

请帮帮我。

这行的人

> a <- 1:10
> getwd()
[1] "C:/Users/saramachandran/Documents"
> save(a,file="Documents/sai.R")
Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
cannot open compressed file 'Documents/sai.R', probable reason 'No such file or directory'
> save(a,file="/Documents/sai.R")
Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
cannot open compressed file '/Documents/sai.R', probable reason 'No such file or directory'
> save(a,file="C:/Users/saramachandran/Documents/sai.R")
> rm(a)
> load("C:/Users/saramachandran/Documents/sai.R")
> print(a)
[1] 1 2 3 4 5 6 7 8 9 10
>

最佳答案

尝试使用:

a <- 1:10
save(a, file = path.expand("~/desktop/Data.Rdata"))
rm(a)
load(path.expand("~/desktop/Data.Rdata"))

编辑:

您发布了以下...

> a <- 1:10
> getwd()
[1] "C:/Users/saramachandran/Documents"
> save(a,file="Documents/sai.R")
Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
cannot open compressed file 'Documents/sai.R', probable reason 'No such file or directory'
> save(a,file="/Documents/sai.R")

问题是工作目录已经在 Documents 中。所以你试图保存到:

 C:/Users/saramachandran/Documents/Documents

这不存在。

改用它(或明确说明您发现的路径):

a <- 1:10
save(a, file = "Data.Rdata")
rm(a)
load("Data.Rdata")

关于r - 将文件加载到 R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15796791/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com