Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R、 使用load()从.rda对象分配内容_R_Types_Load_Rda - Fatal编程技术网

R、 使用load()从.rda对象分配内容

R、 使用load()从.rda对象分配内容,r,types,load,rda,R,Types,Load,Rda,这是非常基本的(我怀疑其他地方也有人问过这一点,尽管不是很清楚) 我有大量的.rda文件,每个文件都有一个数据帧。我想对每个数据帧进行计算,因此需要加载它们(load())。如果是的话,我想: #My data x <- data.frame(a=1:3) y <- data.frame(a=3:6) #Save as RDS saveRDS(x, file = "x.rds") saveRDS(y, file = "y.rds") files <- c("x.rds",

这是非常基本的(我怀疑其他地方也有人问过这一点,尽管不是很清楚)

我有大量的.rda文件,每个文件都有一个数据帧。我想对每个数据帧进行计算,因此需要加载它们(
load()
)。如果是的话,我想:

#My data
x <- data.frame(a=1:3)
y <- data.frame(a=3:6)

#Save as RDS 
saveRDS(x, file = "x.rds")
saveRDS(y, file = "y.rds")

files <- c("x.rds", "y.rds")
data <- lapply(files, readRDS)

#Do something with the data in the list "data"
> # My data
> x <- data.frame(a=1:3)
> y <- data.frame(a=4:6)

> # Save as RDA 
> save(x, file = "x.rda")
> save(y, file = "y.rda")

> files <- c("x.rda", "y.rda")
> data <- lapply(lapply(files, load), get)

> data
[[1]]
  a
1 1
2 2
3 3

[[2]]
  a
1 4
2 5
3 6

您希望将基本
get
函数与以下内容结合使用:

#My data
x <- data.frame(a=1:3)
y <- data.frame(a=3:6)

#Save as RDS 
saveRDS(x, file = "x.rds")
saveRDS(y, file = "y.rds")

files <- c("x.rds", "y.rds")
data <- lapply(files, readRDS)

#Do something with the data in the list "data"
> # My data
> x <- data.frame(a=1:3)
> y <- data.frame(a=4:6)

> # Save as RDA 
> save(x, file = "x.rda")
> save(y, file = "y.rda")

> files <- c("x.rda", "y.rda")
> data <- lapply(lapply(files, load), get)

> data
[[1]]
  a
1 1
2 2
3 3

[[2]]
  a
1 4
2 5
3 6
#我的数据
>x y#另存为RDA
>保存(x,file=“x.rda”)
>保存(y,file=“y.rda”)
>文件数据
[[1]]
A.
1 1
2 2
3 3
[[2]]
A.
1 4
2 5
3 6

如果您确定所有文件只包含一个对象,您可以在如下包装函数中利用
load
envir
参数:

load_object <- function(file) {
  tmp <- new.env()
  load(file = file, envir = tmp)
  tmp[[ls(tmp)[1]]]
}
load\u对象