想象一下,由于存储在data.frame
中的两个模拟产生了2个分布:
sim1 = 1:10
sim2 = 91:100
sim = data.frame(sim1, sim2)
现在,我们希望找到每个分布的10%和90%百分位数。这可以通过以下方式完成:
diffSim = ncol(sim)
confidenceInterval = c(0.1, 0.9)
results = lapply(1:diffSim, function(j) {quantile(sim[, j], confidenceInterval,
names = FALSE, type = 3)})
我想通过引用(data.table
)分配这些结果到:=
。但是,我首先需要使results
处于适当的形状(即1行和4列的data.table)。为此,我随后将unlist
,matrix
和as.data.table
应用于results
:
DT = data.table(Col1 = "Result")
DT[, c("col2", "col3", "col4", "col5") := as.data.table(matrix(unlist(results), nrow = 1))]
我根本不喜欢这个。有没有更短的方法呢?
答案 0 :(得分:0)
不一定更短,但@Ent/ity
public class Vehicle {
@EmbeddedId
private VehicleID vehicleID;
private String description;
@OneToOne(mappedBy="UserID")
private UserInfo userInfo;
// getters and setters..
}
中的所有内容:
data.table
给出:
library(data.table) setDT(sim)[, .(col1 = 'Result', cols = paste0('col',2:5), vals = unlist(lapply(.SD, quantile, probs = confidenceInterval, type = 3))) ][, dcast(.SD, col1 ~ cols, value.var = 'vals')]