0
我在r中写入循环,错误消息来自最后一行: “Match.names(clabs,names(xi))中的错误: 名称不匹配以前的名称“ 最后一行试图保留每个循环的每一行值。感谢大家。如何将每一行添加到循环中的前一行R
a = 20 # resample times
for (id in unique_index){
jeep_id <- jeep_boot[which(jeep$index == id),]
#sample_size is 0.8 of the whole data
sample_size <- floor((0.8)*length(jeep_id$PR))
#bootstrap sample means
samplemeans = rep(NA, a)
for (i in 1:a) {
bootsample.i = sample(jeep_id$PR, sample_size, replace=T)
samplemeans[i] = mean(bootsample.i)
}
#combine mean of 20 sample means and stand dieviation of sample means to be one row
bootresult_id <- cbind(id, mean(samplemeans), sd(samplemeans))
#retain every row value for each round looping
bootresult <- rbind(bootresult, bootresult_id)
}
请考虑提供一些示例数据(以及可能的预期结果)。这样做你会得到更多的回应。我可以创建一个示例数据来测试它。但是,它可能不会模仿您拥有的实际数据集。 – akrun 2014-10-03 04:04:31