[R] transpose and split dataframe

Matthew mccorm@ck @end|ng |rom mo|b|o@mgh@h@rv@rd@edu
Tue Apr 30 21:24:57 CEST 2019

I have a data frame that is a lot bigger but for simplicity sake we can 
say it looks like this:

Regulator    hits
AT1G69490    AT4G31950,AT5G24110,AT1G26380,AT1G05675
AT2G55980    AT2G85403,AT4G89223

    In other words:

data.frame : 2 obs. of 2 variables
$Regulator: Factor w/ 2 levels
$hits         : Factor w/ 6 levels

   I want to transpose it so that Regulator is now the column headings 
and each of the AGI numbers now separated by commas is a row. So, 
AT1G69490 is now the header of the first column and AT4G31950 is row 1 
of column 1, AT5G24110 is row 2 of column 1, etc. AT2G55980 is header of 
column 2 and AT2G85403 is row 1 of column 2, etc.

   I have tried playing around with strsplit(TF2list[2:2]) and 
strsplit(as.character(TF2list[2:2]), but I am getting nowhere.


More information about the R-help mailing list