You specifically said R, but didn't show an attempt at achieving the desired output, or mention that it was part of a larger R script. If this is an assignment, please make an attempt to solve it. So, here's a Python solution (assuming no headers, and that all values are space delimited):
Save as split_mat.py
#!/usr/bin/env python
import sys
with open(sys.argv[1], 'r') as f:
for line in f:
print ' '.join(''.join(i for i in line.strip().split(' ')))
Thanks for your response, its better i do it in R. do you know how its work in R? also to matrix have colnames and row names too.
Why is it better to do it in R? The column headers, and first entry in each row, can easily be printed to the output.
Ok Thanks, im not familiar with python.can you tell me, how i import my file to python and next run the program and then write the results.
also my file have column header and my first column is id that i dont want to change.
there is an error after run code!
File "<stdin>", line 3 print ' '.join(''.join(i for i in line.strip().split(' '))) ^ SyntaxError: invalid syntax
Check your version of python. If you have python 3+, change the print line to have parentheses around the statement, print()
If one column is split into two, how will you handle the headers?
i want to new column have the same name as origin column.
Print() is worked, but python split_mat.py input.txt > output.txt have problem yet.