1

I have a dataframe as such:

sample gender disease treatment
sample1      F     c   starved
sample2      F     d       fed
sample3      M     d   starved
sample4      M     d       fed
sample5      M     c   starved
sample6      M     d       fed

I would like to split the dataframe to obtain one vector per colum with each vector keeping its original column name. This should be a general command (I won't always be applying to this general df).

I know to obtain a simple vector with something like:

gender <- sample$gender

But the file I will need to work with will differ between different experiments and will have different column names and numbers.

I looked at this link but it does not allow you to keep the column names (i.e. the accepted solution forced you to name your vectors Row1, Row2 etc). Any help would be deeply appreciated.

How to split a R data frame into vectors (unbind)

mf94
  • 439
  • 4
  • 19

0 Answers0