I have a data frame called genalex
, because I am trying to put my genetic data into the common "genalex" format. I just used the strsplit
function in R, to split columns, and now I have this:
> genalex[1:5,1:10]
Ind V1 V2 V3 V4 V5 V6 V7 V8 V9
1 100 A A C C N N C C N
2 101 A A C C N N N N N
3 10 A A C C N N C C N
4 11 A A N N N N C C N
5 12 N N N N N N C C G
This data frame actually has 330 rows and 32,068 columns. I would like to replace the name of every other column (V1, V3, V5, V7, V9, etc.) with a NEW name. I would also like to delete every other column name (V2, V4, V6, V8, etc.)
For the new column names, I would like to use the column names from my old data frame, before I split the columns. I will call the old data frame table
. This data frame has 16,034 columns, because it does not include the spaces:
table[1:5,1:5]
X X446043 X539052 X614054 X683054
1 100 A C N C
2 101 A C N N
3 10 A C N C
4 11 A N N C
5 12 N N N C
Therefore, using the old column names from table
, and then adding a space between each column, I ultimately would like for my data frame to look like this, for all 32,068 columns:
> genalex[1:5,1:8]
Ind X446043 X539052 X614054 X683054
1 100 A A C C N N C
2 101 A A C C N N N
3 10 A A C C N N C
4 11 A A N N N N C
5 12 N N N N N N C
Thank you for any help.