简体   繁体   中英

Split a vector element in R

i have vector in this format with just one element:

t1
     [,1]                                                                                                                                                                                                                  
[1,] "<meta','name','description','content','Compre','ingressos','para','FEIRA','DIGITAL','EXPO','SP','2022','em','São','Paulo','dia','14','de','julho.','Confira','os','melhores','eventos','de','2022','na','Sympla!>\n"

and i need to split this into a vector with many elements, which are separated by comma, the purpose is to create a transactional dataframe to use with arules.

Could you help me? Thanks

我认为它是矩阵 1X1 所以试试

strsplit(t1[1] , ",")

It seems you have a single string in a 1x1 matrix. If you want to extract the words into a vector, with the quotes and angle brackets removed, you can do:

gsub('<|>|\n|\\!', "", strsplit(c(t1), "','")[[1]])
#>  [1] "meta"        "name"        "description" "content"     "Compre"     
#>  [6] "ingressos"   "para"        "FEIRA"       "DIGITAL"     "EXPO"       
#> [11] "SP"          "2022"        "em"          "São"        "Paulo"      
#> [16] "dia"         "14"          "de"          "julho."      "Confira"    
#> [21] "os"          "melhores"    "eventos"     "de"          "2022"       
#> [26] "na"          "Sympla"

Created on 2022-06-14 by the reprex package (v2.0.1)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM