【发布时间】:2022-12-02 00:47:44
【问题描述】:
I have this data frame:
> d
gene_pair
1 ABHD4_ABHD5
2 ABL1_ABL2
3 ABR_BCR
4 ACAP2_ACAP3
5 ACTX_ACTR1B
6 ACVR2A_ACVR2B
This is the dput:
> dput(d)
structure(list(gene_pair = c("ABHD4_ABHD5", "ABL1_ABL2", "ABR_BCR",
"ACAP2_ACAP3", "ACTX_ACTR1B", "ACVR2A_ACVR2B")), row.names = c(NA,
6L), class = "data.frame")
I would like to create a new column called sorted gene pair, where I make sure the genes are in alphabetical order.
I have tried:
d %>%
rowwise() %>%
mutate(paste(sort(strsplit(gene_pair, '_')), collapse = '_'))
But I get an atomic error
Expected outcome of the sorted_gene_pair column:
> d
sorted_gene_pair
1 ABHD4_ABHD5
2 ABL1_ABL2
3 ABR_BCR
4 ACAP2_ACAP3
5 ACTR1B_ACTX
6 ACVR2A_ACVR2B
【问题讨论】: