R 如何快速创建所有组合字符串值的变量;数据帧中某个特定列的?
temp_day是数据帧,它有十亿行R 如何快速创建所有组合字符串值的变量;数据帧中某个特定列的?,r,string,bigdata,paste,accumulator,R,String,Bigdata,Paste,Accumulator,temp_day是数据帧,它有十亿行 Height_classify <- data.frame(color = c('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'), min = c(0, 100,300,500,1000,2000,5000), max = c(100,300
Height_classify <- data.frame(color = c('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'),
min = c(0, 100,300,500,1000,2000,5000),
max = c(100,300,500,1000,2000,5000,8000))
make_code <- function(temp_day, h_class){
temp_class <- Height_classify %>% filter(color == h_class)
min_godo <- temp_class[1,2]
max_godo <- temp_class[1,3]
temp_day_hight <- temp_day %>% filter(AltitudeActual_m >= min_godo & AltitudeActual_m < max_godo)
polys <- stri_c("polys_", temp_class[1,1], " = [")
hight_flight <- as.data.frame(table(unlist(temp_day_hight$mdH_CallSign)), stringsAsFactors = F)
for (sFlight in hight_flight$Var1){
temp_day_hight_flight <- temp_day_hight %>% filter(mdH_CallSign == sFlight)
if (nrow(temp_day_hight_flight) >1){
polys <- stri_c(polys, "[")
for (i in 1:nrow(temp_day_hight_flight)){
polys <- stri_c(polys, temp_day_hight_flight$coord[i])
if (i < nrow(temp_day_hight_flight)){
polys <- stri_c(polys, ", ")
} else {
polys <- stri_c(polys, "], ")
}
} # for i
} # if
}# for sFlight
polys <- substr(polys, 1, nchar(polys)-2)
polys <- stri_c(polys, "]\n\n")
return(polys)
}
我的英语不好。请理解这句话是否有误。如果没有原始数据帧,很难提供解决方案,但对于大型数据帧(>10万行)上的操作,执行类似于嵌套for循环的操作将非常低效,更不用说10亿行了。如果您的数据集是
polys <- stri_c(polys, temp_day_hight_flight$coord[i])