data.table中包含list类型列的错误消息

时间:2016-03-03 17:22:31

标签: r data.table

对于示例数据框:

df1 <- structure(list(country = list("PL", "PL", "PL", "PL", "SE", "SE", 
                                     "SE", "SE", "SE", "SE", "SE", "SE"), 
                  region = c("PL42", "PL34", 
                             "PL33", "PL62", "SE22", "SE32", "SE11", "SE31", "SE23", "SE12", 
                               "SE21", "SE33"), 
                   N = c(59L, 55L, 59L, 48L, 233L, 91L, 406L, 148L, 
                         323L, 248L, 163L, 104L), 
                     freq.1 = c(31L, 34L, 37L, 27L, 109L, 
                                 53L, 175L, 82L, 169L, 134L, 80L, 51L), result = c(53.52, 61.2, 
                                                                                                                                                                                                  63.24, 55.7, 46.78, 58.24, 43.1, 55.41, 52.32, 54.03, 49.08, 
                                                                                                                                                                                                  49.04), level = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), .Names = c("country", 
                                                                                                                                                                                                                                                                     "region", "N", "freq.1", "result", "level"), class = c("data.table", 
                                                                                                                                                                                                                                                                                                                            "data.frame"), row.names = c(NA, -12L))

我想应用一个简短的函数来生成一个汇总表:

variable.country <-setDT(df1)[order(country), 
                                           list(min_result = min(result),
                                                no.regions =.N,
                                                max_result = max(result), 
                                                level= level[1L]), 
                                           by = country]

但我收到错误:

Error in forder(x, country) : 
  Column '1' is type 'list' which is not supported for ordering currently.

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:4)

“国家/地区”列是elements = [ element.strip(' -') for element in config["PATHS"]["elements"].strip().split('\n')] 。我们可以list列,它应该可以正常工作

unlist