Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R data.table中列类型为list的错误消息_R_Data.table - Fatal编程技术网

R data.table中列类型为list的错误消息

R data.table中列类型为list的错误消息,r,data.table,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"

对于示例数据帧:

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))
如何解决此问题?

国家/地区列是一个
列表。我们可以
unlist
列,它应该可以正常工作

df1[, country:= unlist(country)][order(country), 
                           list(min_result = min(result),
                                no.regions =.N,
                                max_result = max(result), 
                                level= level[1L]), .(country)]
#   country min_result no.regions max_result level
#1:      PL      53.52          4      63.24     2
#2:      SE      43.10          8      58.24     2

你的对象名是
df1
,而不是
df
,我已经厌倦了编辑混乱的数据帧格式。你的责任。或者如果是打字错误,那么你应该删除。国家栏是一个
列表
Error in forder(x, country) : 
  Column '1' is type 'list' which is not supported for ordering currently.
df1[, country:= unlist(country)][order(country), 
                           list(min_result = min(result),
                                no.regions =.N,
                                max_result = max(result), 
                                level= level[1L]), .(country)]
#   country min_result no.regions max_result level
#1:      PL      53.52          4      63.24     2
#2:      SE      43.10          8      58.24     2