Re: [R] Fwd: Re: transpose and split dataframe

2019-05-06 Thread Matthew
Thank you very much Jim and David for your scripts and accompanying explanations. I was intrigued at the results that came from David's script.  As seen below where I have taken a small piece of his DataTable: AT1G69490 AT1G29860    AT4G18170 *AT5G46350* AT1G01560    0    0    0    1 *AT1G02920

Re: [R] Fwd: Re: transpose and split dataframe

2019-05-02 Thread Jim Lemon
Hi again, Just noticed that the NA fill in the original solution is unnecessary, thus: # split the second column at the commas hitsplit<-strsplit(mmdf$hits,",") # get all the sorted hits allhits<-sort(unique(unlist(hitsplit))) tmmdf<-as.data.frame(matrix(NA,ncol=length(hitsplit),nrow=length(allhit

Re: [R] Fwd: Re: transpose and split dataframe

2019-05-02 Thread Jim Lemon
Hi Matthew, I'm not sure whether you want something like your initial request or David's solution. The result of this can be transformed into the latter: mmdf<-read.table(text="Regulator hits AT1G69490 AT4G31950,AT5G24110,AT1G26380,AT1G05675,AT3G12910,AT5G64905,AT1G22810,AT1G79680,AT3G02840,AT5G2

Re: [R] Fwd: Re: transpose and split dataframe

2019-05-02 Thread David L Carlson
We still have only the toy version of your data from your first email. The second email used dput() as I suggested, but you truncated the results so it is useless for testing purposes. Use the following code after creating DataList (up to mx <- ... ) in my earlier answer: n <- sapply(DataList,

Re: [R] Fwd: Re: transpose and split dataframe

2019-05-01 Thread Matthew
Thank you very much, David and Jim for your work and solutions. I have been working through both of them to better learn R. They both proceed through a similar logic except David's starts with a character matrix and Jim's with a dataframe, and both end with equivalent dataframes (  identical(tm

Re: [R] Fwd: Re: transpose and split dataframe

2019-04-30 Thread David L Carlson
If you read the data frame with read.csv() or one of the other read() functions, use the asis=TRUE argument to prevent conversion to factors. If not do the conversion first: # Convert factors to characters DataMatrix <- sapply(TF2list, as.character) # Split the vector of hits DataList <- sapply(