简体   繁体   English

R 中的行到列观察

[英]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.

相关问题 在 R 中将列更改为连续观察 - Changing a Column to an Observation in a Row in R 在 R 中将特定的观察和行变成列 - Turn Specific Observation and Row into Column in R 复制观察 r 中另一列中每一行的列 - replicate observation of column for each row in another columns in r 在R的另一列的行尾追加观察 - Append observation at end of row from another column in R 如何计算每行特定观察的数量并添加到R中的最后一列? - How to calculate the number of specific observation each row and add to the last column in R? R日期顺序-不按天增加,而是按行/观察数增加 - R date sequence - increase not by days but by row/observation 如何不使用第一次观察作为 R 中的列名? - How to not use first observation as column names in R? 使用R将单个柱分成多个观察 - Splitting a single column into multiple observation using R R - 对于列中的每个观察值,在另一列中找到最接近的观察值 - R - for each observation in a column, find the closest one in another column 从不同列中的另一个观察值中减去一个观察值,并将特定值添加到结果中以在 R 的第一列中创建一个新观察值 - Subtract an observation from another in different column and add a specific value to the result to create a new observation in the first column in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM