我有以下面板数据,其中一些人的观察比其他人多。
id <- c("John","John","John","John","John",
"Mike","Mike","Mike","Mike",
"Andrea","Andrea","Andrea","Andrea","Andrea","Andrea","Andrea")
time <- c(1:5, 1:4, 1:7)
observation <- c(rnorm(1:5), rnorm(1:4), rnorm(1:7))
paneldata <- data.frame(id, time, observation)
我想计算个人之间观察的相关性。R 应该忽略缺失的观察结果,例如
Mike 和 John 之间的相关性:只应考虑时间 1 到 4
John 和 Andrea 之间的相关性:仅时间 1 到 5 等。
实现这些结果的最佳方法是什么?