1

I have data in a csv file in a single column with 6954 values. I want to split this column into multiple columns such that each column has 122 data and next column has the next 122 data and so on. I guess, I will have a final matrix of 122 rows and 57 columns. Any help will be appreciated.

Thanks

1

3 Answers 3

3

Like this ?

x <- rep(1:122, 5)
xx <- matrix(x, nrow=122)
xx[1:5, ]
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    1    1    1
[2,]    2    2    2    2    2
[3,]    3    3    3    3    3
[4,]    4    4    4    4    4
[5,]    5    5    5    5    5
Sign up to request clarification or add additional context in comments.

Comments

1

Or this will do the trick as well:

x = 1:6954
dim(x) <- c(122, 57)

Comments

1

A column can be split using the colsplit function which is part of the reshape package http://r.ramganalytics.com/r/split-a-column-by-a-character-using-colsplit-function/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.