I want to split values contained in a single column into new columns.
I have some data that looks like this in a file:
> df
V1
1 00006303657102064942660780914135165036 12867 15476 15473 15474 15397 14050
2 00006319625527159782351492300309533775 12867 15473 13678 13497 15397
3 00006327933867965144524703512179615086 12867 14245 15397 15473 15474
I'd like to separate each value into a new column : V1, V2, V3, V4, V5 and V6
I tried :
df2 <- data.frame(do.call('rbind', strsplit(as.character(df$V1), ' ', fixed = FALSE)))
I end up with output like this:
X1 X2 X3 X4 X5 X6
1 00006303657102064942660780914135165036 12867 15476 15473 15474 15397
2 00006319625527159782351492300309533775 12867 15473 13678 13497 15397
3 00006327933867965144524703512179615086 12867 14245 15397 15473 15474
X7 X8
1 14050 00006303657102064942660780914135165036
2 00006319625527159782351492300309533775 12867
3 00006327933867965144524703512179615086 12867
Some of the v1 values end up in other columns. It may be happening because there is no space at the end of the row. How can i execute this correctly?
thanks