I have a dataframe which has all observations in one column and looks like this;
[1] "1"
[2] "201"
[3] " van Aert WoutTeam Jumbo-Visma "
[4] "25"
[5] "Team Jumbo-Visma"
[6] "300"
[7] "200"
[8] "4:58:564:58:56"
[9] "2"
[10] "234"
[11] " Formolo DavideUAE-Team Emirates "
[12] "27"
[13] "UAE-Team Emirates"
[14] "250"
[15] "150"
[16] "0:300:30"
[17] "3"
[18] "87"
[19] " Schachmann MaximilianBORA - hansgrohe "
[20] "26"
[21] "BORA - hansgrohe"
[22] "215"
[23] "120"
[24] "0:320:32"
[25] "4"
[26] "111"
[27] " Bettiol AlbertoEF Pro Cycling "
[28] "26"
[29] "EF Pro Cycling"
[30] "175"
[31] "100"
[32] "1:311:31"
[33] "5"
[34] "44"
[35] " Fuglsang JakobAstana Pro Team "
I want to create columns for the every 1-8 observations and tried several options but without success.
All suggestions to split observations from one column into multiple columns are welcome.
I miss your example data defined with the code, let's assume it is called df
, You could use matrix function and define number of columns.
t(matrix(ncol = 8, as.character(df[,1])) #to get variables in columns, you need to transpose the matrix with t() function.
You can subsequently transform it to data.frame with as.data.frame
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.