I have a data frame like this:
data.frame(x = c(">Seq1", ">Seq2"), y = c("AAAA", "BBBB"))
Wished output:
data.frame(x = c(">Seq1", "AAAA", ">Seq2", "BBBB"))
Thank you in advance!
CodePudding user response:
library(dplyr)
data.frame(x = c(">Seq1", ">Seq2"), y = c("AAAA", "BBBB")) %>%
rowwise() %>%
summarise(x = c(x,y))
x
<chr>
1 >Seq1
2 AAAA
3 >Seq2
4 BBBB
CodePudding user response:
Using base R
, just t
ranspose the data, convert to a vector (c
) and create a new data.frame
data.frame(x = c(t(df1)))
-output
x
1 >Seq1
2 AAAA
3 >Seq2
4 BBBB
data
df1 <- data.frame(x = c(">Seq1", ">Seq2"), y = c("AAAA", "BBBB"))
CodePudding user response:
library(tidyr)
data.frame(x = c(">Seq1", ">Seq2"), y = c("AAAA", "BBBB")) |>
pivot_longer(everything()) |>
subset(select=-name)
value
<chr>
1 >Seq1
2 AAAA
3 >Seq2
4 BBBB