我对R很新,只是无法调试我得到的一个错误:
Error in combn(nrow(current_data), 2) : n < m
我正在根据赛鸽数据创建坐标计算。
# foreach loft, estimate the lat/long
for(i in 1:nrow(loft_coord)){
#print(i)
# get current loft to calculate coords for
current_loft <- as.character(loft_coord[i,1])
# if n_races is only 1, then dont calculate coord (no info, so we leave as NA)
if(loft_coord[i,2] == 1){
next
} else {
# Get lat, lon, dist info for current loft from races
current_data <- races %>% filter(loft %in% current_loft) %>%
select(loft, lat, long, distance)
# define all pair combinations of races
pair_combinations <- t(combn(nrow(current_data), 2))
coord_input_data <- cbind(current_data[pair_combinations[,1],],
current_data[pair_combinations[,2], c(2,3,4)])
colnames(coord_input_data) <- c("loft", "lat_x", "long_x", "dist_x","lat_y",
"long_y", "dist_y")
# define empty matrix to store estimates coords for the current loft in
consideration
estimated_coords <- matrix(NA, nrow = nrow(coord_input_data), ncol = 2)
它执行直到合并......代码卡在那里
非常感谢您的帮助!
祝你好运, 斯泰西