[英]Observation in Row to Column in R
I have a dataframe which has all observations in one column and looks like this;我有一个 dataframe 在一列中包含所有观察结果,看起来像这样;
[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.我想为每 1-8 个观察创建列并尝试了几个选项但没有成功。
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.我想念您用代码定义的示例数据,假设它被称为df
,您可以使用矩阵 function 并定义列数。
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
.您随后可以使用as.data.frame
将其转换为 data.frame。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.