PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 13, 2022

[FIXED] How to get every element from 1-15 into a list from a vector that has over 800 elements, in R

 August 13, 2022     list, r, vector     No comments   

Issue

I have a vector named all_teams.

   [1] "Arizona Cardinals"        "1920"                     "2022"                     "577"                     
   [5] "777"                      "41"                       ".426"                     "11"                      
   [9] "7"                        "10"                       "0.412"                    "2"                       
  [13] "0"                        "1"                        "8"                        "Chicago Cardinals"       
  [17] "1920"                     "1943"                     "99"                       "141"                     
  [21] "21"                       ".413"                     "0"                        "0"                       
  [25] "0"                        ""                         "1"                        "0"                       
  [29] "0"                        "1"                        "Chi/Pit Cards/Steelers"   "1944"                    
  [33] "1944"                     "0"                        "10"                       "0"                       
  [37] ".000"                     "0"                        "0"                        "0"                       
  [41] ""                         "0"                        "0"                        "0"                       
  [45] "0"                        "Chicago Cardinals"        "1945"                     "1959"                    
  [49] "66"                       "107"                      "4"                        ".382"                    
  [53] "2"                        "1"                        "1"                        ""                        
  [57] "1"                        "0"                        "0"                        "2"   

I am trying to figure out how to extract 1-15 elements into a list and my desired output is:

[1] "Arizona Cardinals"        "1920"                     "2022"                     "577"                     
    "777"                      "41"                       ".426"                     "11"                      
    "7"                        "10"                       "0.412"                    "2"                       
    "0"                        "1"                        "8"                        
[2] "Chicago Cardinals"        "1920"                     "1943"                     "99"                       
    "141"                      "21"                       ".413"                     "0"                        
    "0"                        "0"                        ""                         "1"                        
    "0"                        "0"                        "1"                        
[3] "Chi/Pit Cards/Steelers"   "1944"                     "1944"                     "0"                        
    "10"                       "0"                        ".000"                     "0"                        
    "0"                        "0"                        ""                         "0"                        
    "0"                        "0"                        "0"                        
[4] "Chicago Cardinals"        "1945"                     "1959"                     "66"                       
    "107"                      "4"                        ".382"                     "2"                        
    "1"                        "1"                        ""                         "1"                        
    "0"                        "0"                        "2"

Any help is greatly appreciated!


Solution

Convert to matrix and then split by column:

asplit(matrix(all_teams, nrow = 15), 2)

With toy data:

asplit(matrix(1:60, nrow = 15), 2)

output:

[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15

[[2]]
 [1] 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

[[3]]
 [1] 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

[[4]]
 [1] 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60


Answered By - Maël
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,208,654

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing