【发布时间】:2023-03-13 07:10:02
【问题描述】:
我有一个无限长的df。下面的示例只有 2 个特征:“密度”和“脂质”,但其他 dfs 可能有 50 个或更多特征。每个 trait 都有 3 列与之关联:value.trait、unit.trait、method.trait。 Seems very similiar to this example in vignette 但是当我运行下面的代码时,我不断收到错误:输入必须是向量,而不是 NULL
3行样本数据
x <- structure(list(geno_name = c("MB mixed", "MB mixed", "MB mixed"
), study_location = c("lab", "lab", "lab"), author = c("test",
"test", "test"), value.lipids = c(NA, 2.361463603, 1.461189384
), unit.lipids = c(NA, "g cm^-2", "g cm^-2"), method.lipids = c(NA,
"airbrush", "airbrush"), value.density = c(1.125257337, 0.816034359,
0.49559013), unit.density = c("g cm^-3", "g cm^-3", "g cm^-3"
), method.density = c("3D scanning", "3D scanning", "3D scanning"
)), row.names = c(NA, 3L), class = "data.frame")
当前枢轴代码:
x %>%
select(!c(study_location, author)) %>%
pivot_longer(cols = !geno_name,
names_to = c(".value", "trait"),
names_sep = ".",
values_drop_na = TRUE)
错误代码:
错误:输入必须是向量,而不是 NULL。运行
rlang::last_error()到 查看错误发生的位置。另外:警告信息:1:在 gsub(paste0("^", names_prefix), "", names(cols)) : 参数 'pattern' 的长度 > 1 并且仅使用第一个元素 2: 预计2件。在 6 行 [1, 2, 3, 4, 5, 6]。
【问题讨论】:
-
请make this question reproducible 以纯文本格式包含示例数据 - 例如来自
dput(yourdata)的输出。我们无法从图像中复制/粘贴数据。 -
names_sep = "\\."中的句号需要转义
标签: r