I have a text file that has one colunm of 1800 entries that are actually two sets of data (size,age) that have been combined. The first number (row1,column1) is size 1, the second number (row2,column1) is age1, the third column (row3,column1) is size 2, the fourth number (row4,column1) is age2, and so on. Does anyone know how to split this into a matrix of two columns of 900 entries each?
0
votes
3 Answers
2
votes
1
votes
1
votes
If you have a single vector x
containing your alternating size and age data:
df <- do.call(data.frame, split(x, c("size", "age")))
If you want 2-column matrix instead, use cbind
:
df <- do.call(cbind, split(x, c("size", "age")))
This isn't the most efficient way, but it does automatically give you column names for free.
read.table
andread.csv
, but if you can post some of said file, I could tell you for sure! - Justin