Entering edit mode
3.8 years ago
georgia.stavrou
•
0
Hi Biostars,
I have been trying to merge two columns into a single column in R but I think I am missing something.
My dataframe looks something like this:
> df
Gene_name Sequence
GAPDH ATTTCGGGA
ENAM GGGCTTACG
KRAS AAATGCTTTC
I would like to create a single-column dataframe that will show the gene and the sequence right underneath like so:
> Merge
GAPDH
ATTTCGGGA
ENAM
GGGCTTACG
KRAS
AAATGCTTTC
Ive tried this: test<-cat(df$Gene_name,"\n",df$Sequence)
Doesnt seem to work..
Any ideas?
Many thanks, Gina
Do you want an actual new line or have all in the same column?
Something like
df %>% transmute(col1 = paste0(col1, ",", col2)) %>% separate_rows(col1, sep = ",")
? (The packages you'll need for this aremargittr
,dplyr
, andtidyr
.)I think you can use
sed
or something similar to convert spaces/tabs to newlines.Converting df to parsable formats are better. Please try below:
This way, you can further manipulate fasta in R.