Skip to content
Prev 379497 / 398503 Next

transpose and split dataframe

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(tmmdf, TF2list2)) returns TRUE? ). They have 
both been very helpful. However, there is one attribute of my intended 
final dataframe that is missing.

Looking at part of the final dataframe:

 ?head(tmmdf)
 ? AT1G69490 AT1G29860 AT1G29860.1 AT4G18170 AT4G18170.1 AT5G46350
1 *AT4G31950* *AT4G31950*?? AT5G64905 *AT4G31950* AT5G64905 *AT4G31950*
2 AT5G24110 AT5G24110?? AT1G21120 AT5G24110?? AT1G14540 AT5G24110
3 AT1G26380 AT1G05675?? AT1G07160 AT1G05675?? AT1G21120 AT1G05675

Row 1 has *AT4G31950* in columns 1,2,4 and 6, but AT4G31950 in columns 3 
and 5. What I was aiming at would be that each row would have a unique 
entry so that AT4G31950 is row 1 columns 1,2,4 and 6, and NA is row 1 
columns 3 and 5. AT4G31950 is row 2 columns 3 and 5 and NA is row 2 
columns 1,2,4 and 6. So, it would look like this:

 ?head(intended_df)
 ? AT1G69490 AT1G29860 AT1G29860.1 AT4G18170 AT4G18170.1 AT5G46350
1 AT4G31950 AT4G31950???? NA ? ? ? ? ? ? ?? AT4G31950? ? ?? NA ? ? ? ? 
AT4G31950

2 ? ?? NA ? ? ? ? ? ? ?? NA ? ? ? ? ? AT4G31950 ? ? ? NA ? ? ? ? ?? 
AT4G31950 ? ?? NA

I have been trying to adjust the code to get my intended result 
basically by trying to build a dataframe one column at a time from each 
entry in the character matrix, but have not got anything near working yet.

Matthew

On 4/30/2019 6:29 PM, David L Carlson wrote