【发布时间】:2020-01-14 16:51:56
【问题描述】:
我想将 R 中数据框的一列拆分为多列。蛋白质组学数据的 table$Description 有许多行,如下所示:
Vimentin OS=Homo sapiens GN=VIM PE=1 SV=4
最好将此表$Description 拆分为 5 个单独的列,分别命名为“protein”、“OS”、“GN”、“PE”和“SV”。
我尝试了以下方法:
separate(table, Description, c("protein","OS","GN","PE","SV"),sep = c(' OS=',' GN=',' PE=',' SV='), convert = TRUE)
输出仅填充蛋白质和操作系统列,但其他填充为 N/A。 错误信息如下:
1: In stringi::stri_split_regex(value, sep, n_max) :
longer object length is not a multiple of shorter object length
2: Expected 5 pieces. Missing pieces filled with `NA` in 11149 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
有人知道如何调整代码吗?
【问题讨论】: