简体   繁体   English

这个警告消息“用剩余物回收”在 R 中是什么意思?

[英]What does this warning message"recycled with remainder" mean In R?

警告消息:在 as.data.table.list(x, keep.rownames = keep.rownames, check.names = check.names, : 项目 2 有 1650197 行,但最长的项目有 1667524;与剩余部分回收。

This warning arises when R is given some form of list input to produce some form of list output but the length of the input and output lengths do not match.当 R 被赋予某种形式的列表输入以产生某种形式的列表输出但输入长度和输出长度不匹配时,就会出现此警告。 In these cases, R repeats and reuses the shorter list as appropriate.在这些情况下,R 会根据需要重复并重用较短的列表。

See the documentation here : "If a list is supplied, each element is converted to a column in the data.table with shorter elements recycled automatically."请参阅此处的文档:“如果提供了列表,则每个元素都将转换为 data.table 中的一列,并自动回收较短的元素。”

However, if the longer list is not a multiple of the length of the shorter list then the difference in length lists is unlikely to be deliberate, hence this warning.但是,如果较长的列表不是较短列表长度的倍数,则长度列表的差异不太可能是故意的,因此出现此警告。

Some examples:一些例子:

> library(data.table)
> example1 = list(x = c(1,2,3,4,5,6), y = 3)
> as.data.table(example1)
   x y
1: 1 3
2: 2 3
3: 3 3
4: 4 3
5: 5 3
6: 6 3

> example2 = list(x = c(1,2,3,4,5,6), y = c('a','b'))
> as.data.table(example2)
   x y
1: 1 a
2: 2 b
3: 3 a
4: 4 b
5: 5 a
6: 6 b

In both of these examples, the x and y lists are of different lengths, so the y list has been repeated.在这两个示例中, xy列表的长度不同,因此重复了y列表。 This produces no warning as y is length 1 or 2 which is a multiple of x which is length 6.这不会产生警告,因为y的长度为 1 或 2,它是x的倍数,即长度为 6。

> example3 = list(x = c(1,2,3,4,5,6), y = c('a','b','c','d'))
> as.data.table(example3)
   x y
1: 1 a
2: 2 b
3: 3 c
4: 4 d
5: 5 a
6: 6 b
Warning message:
In as.data.table.list(example3) :
  Item 2 has 4 rows but longest item has 6; recycled with remainder.

But this example x is length 6 and y is length 4. So only the first two terms of y have been repeated when creating the data table.但是这个例子中x的长度为 6, y的长度为 4。所以在创建数据表时只重复了y的前两项。 R gives a warning as not every term in y has been reused the same number of times. R 给出警告,因为并非y每个术语都被重复使用了相同的次数。

In your example instead of lengths 6 and 4, you have columns of length 1650197 and 1667524. As it is unlikely (but possible) that you wanted to repeat the first 17327 entries (1667524 - 1650197) of the shorter column, R gives you a warning to prompt to you check your input columns.在您的示例中,而不是长度 6 和 4,您有长度为 1650197 和 1667524 的列。由于您不太可能(但可能)想要重复较短列的前 17327 个条目(1667524 - 1650197),R 为您提供警告提示您检查输入列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM