separate_rows exampleCreate some fake data:
d <- data.frame(
organism=c("Grasshopper", "Bumblebee", "MycoTB"),
protein=c("Jumpylegs", "venom-1", "rpoB"),
accession=c("Gr1,Gr2,Gr3", "Bbv4,Bbv5,Bbv6", "Mtb1,Mtb2,Mtb3,Mtb4,Mtb5")
)
This is what your data looks like:
d
## organism protein accession
## 1 Grasshopper Jumpylegs Gr1,Gr2,Gr3
## 2 Bumblebee venom-1 Bbv4,Bbv5,Bbv6
## 3 MycoTB rpoB Mtb1,Mtb2,Mtb3,Mtb4,Mtb5
One command to “separate” rows by the comma in the accession column:
library(tidyr)
separate_rows(d, accession, sep=",")
## organism protein accession
## 1 Grasshopper Jumpylegs Gr1
## 2 Grasshopper Jumpylegs Gr2
## 3 Grasshopper Jumpylegs Gr3
## 4 Bumblebee venom-1 Bbv4
## 5 Bumblebee venom-1 Bbv5
## 6 Bumblebee venom-1 Bbv6
## 7 MycoTB rpoB Mtb1
## 8 MycoTB rpoB Mtb2
## 9 MycoTB rpoB Mtb3
## 10 MycoTB rpoB Mtb4
## 11 MycoTB rpoB Mtb5