r - 无法分配向量 - lapply 函数
问题描述
使用这个函数,我从整个 df 中减去每一列。现在df太大了,我总是收到错误消息:无法分配大小的向量。是否有可能将任务拆分为不同的部分以获得相同的结果?
或者知道我能做什么?df 约为 2500 列。
感谢您的任何建议或帮助!!
CX <- lapply(df, function(x) df - x)
更新:
library("dplyr")
library("tidyverse")
library("dlookr")
library("plyr")
library("readxl")
library("qpcR")
library("ggplot2")
library("matrixStats")
ZZ <- data.frame( Date = c("05-01-2001", "05-02-2001", "05-03-2001", "05-04-2001", "05-06-2001"),
Paris = c(25.3, 25.4, 26, 26.1, 25.6),
Berlin = c(18.5, 18.1, 19, 20.1, 23.9),
Tokyo = c(23.6, 23.9, 26, 26.5, 27),
Funchal = c(33.7, 32, 32.1, 31.4, 30.5),
Penaforte = c(26.1, 26, 26, 26.4, 26.1))
memory.limit(9999999999999) #
ZZ500 <- select_if(ZZ, is.numeric)
getDiff <- function(ZZ, idx) {
#This is the function to calculate all the temperature diffs
num.rows <- nrow(ZZ)
output.range <- 1:(num.rows-1)
diff1 <- ZZ[output.range,1:ncol(ZZ)]
diff2 <- ZZ[output.range+idx,1:ncol(ZZ)]
diff3 <- data.frame(((diff1) / (diff2) -1))
return(diff3)
}
out <- lapply(1:4, function(x) getDiff(ZZ500, x)) # calculates all diffs over a several period (here 1 to 4 days)
All_Diffs <- as.data.frame(out)
All_Diffs_V1 <- All_Diffs
for(i in 1:ncol(All_Diffs_V1)){ #Negative changes = 0, Positive changes = 1
All_Diffs_V1[ ,i] <- ifelse (All_Diffs_V1[ ,i] > 0, 1, 0)
}
df <- All_Diffs_V1
result <- lapply(df, function(x) df - x) # Subtract all the columns, possible results: 1,0,-1
result.df <- data.frame(result)
最后一部分不包括在内。在这一部分中,我试图找出一个例子:每年 5 月 16 日有多少次巴黎和东京之间的温度是负值或正值,以及每一列对、每一天和每个时间段的温度。
解决方案
推荐阅读
- css - 在css中使用背景颜色突出显示选定的对象
- java - JSP 文件未在 Spring Boot 应用程序中呈现
- java - java.lang.ClassNotFoundException: javax.servlet.Filter
- php - 无法让 Laravel/Homestead 工作——在浏览器中显示
- parallel-processing - 在非键控 Flink 流中实施良好平衡的并行性
- http-headers - Istio 和 HTTP 主机头
- mongodb - MongoDB 聚合仅返回特定字段
- docker - 无法在我公司的 GPU 集群上从 torchvision 加载模型
- r - 对因子变量和逻辑进行排名
- angular - 如何使用带有角度参数的rest api方法GET