我有以下 Dataframe
temp = structure(list(pid = c("s1", "s1", "s1"), LEFT_GENE = c("PTPRO", "EPS8", "DPY19L2,AC084357.2,AC027667.1"
), RIGHT_GENE = c("", "FOx,D", "DPY19L2P2,S100A11P1")), row.names = c(1L, 2L, 3L), class = "data.frame")
pid LEFT_GENE RIGHT_GENE
1 s1 PTPRO
2 s1 EPS8 FOx, D
3 s1 DPY19L2,AC084357.2,AC027667.1 DPY19L2P2,S100A11P1
我想将每个用逗号分隔的项目拆分成一个新行并创建新的组合。例如,最后一行应该创建6个新的附加行。但是,我得到这个错误,我不明白。
temp %>%
separate_rows(LEFT_GENE:RIGHT_GENE, sep=",") %>%
data.frame ( stringsAsFactors = F)
Error in `fn()`:
! In row 3, can't recycle input of size 3 to size 2.
Run `rlang::last_error()` to see where the error occurred.
但是,错误似乎来自第3行,因为第1:2行工作正常
> temp[1:2,
+ ] %>%
+ separate_rows(LEFT_GENE:RIGHT_GENE, sep=",") %>%
+ data.frame ( stringsAsFactors = F)
pid LEFT_GENE RIGHT_GENE
1 s1 PTPRO
2 s1 EPS8 FOx
3 s1 EPS8 D
有人知道问题出在哪吗?
2条答案
按热度按时间ljsrvy3e1#
一次只能分隔一列
2ul0zpep2#
如果需要6行,则选项为
如果
NA
应替换为之前的非NA,则在末尾添加fill