【发布时间】:2020-03-12 03:31:45
【问题描述】:
如果不共享私人数据,我无法提供可重现的示例。由于我不知道为什么会发生这种情况,我也无法模仿数据来重现。
我对数据框进行了 dplyr 转换:
combined_grp <- combined %>%
mutate(temp = 1) %>%
pivot_wider(names_from = TTI_Bin_John,
names_prefix = "TTI_",
values_from = temp,
values_fn = as.numeric,
values_fill = list(temp = 0))
这会返回一个警告:
Warning message:
Values in `temp` are not uniquely identified; output will contain list-cols.
* Use `values_fn = list(temp = list)` to suppress this warning.
* Use `values_fn = list(temp = length)` to identify where the duplicates arise
* Use `values_fn = list(temp = summary_fun)` to summarise duplicates
我尝试通过在上面的块末尾添加这个来改变输出列:
%>% mutate_at(vars(matches("TTI_(<|>)")), as.numeric)
但这会引发错误:
values_fn[[value]] 中的错误:'builtin' 类型的对象不是子集
有没有人认识到这个错误或者我可以如何解决它,以便更广泛地旋转的新功能是数字而不是列表?
【问题讨论】:
-
您在输出
x <- tribble(~name, ~value, "a", 1, "b", 2, "a", 3); pivot_wider(x)中的某些位置有重复值。如果您可以匿名数据并将其包含在内,那将很有用 -
您可以多次向数据添加随机数,使其完全不同
-
使用了
mutate(id = row_num),这似乎解决了我的问题。但我不明白为什么我必须这样做