R: read the first column and then the rest -


i have file codes , descriptions. code short (3-6 characters) string of letters, separated following description space. description several words (also spaces). here example:

liiss license issued limod license modified lipass license assigned (partial assignment) lipnd license assigned (partition/disaggregation) lippnd license issued partial/p&d assignment lipur license purged lirein license reinstated liren license renewed 

i'd read 2-column data frame code in first column , description in second one. how can r?

you use stri_split_fixed() stringi

library(stringi) as.data.frame(stri_split_fixed(readlines("x.txt"), " ", n = 2, simplify = true)) #       v1                                           v2 # 1  liiss                               license issued # 2  limod                             license modified # 3 lipass        license assigned (partial assignment) # 4  lipnd  license assigned (partition/disaggregation) # 5 lippnd license issued partial/p&d assignment # 6  lipur                               license purged # 7 lirein                           license reinstated # 8  liren                              license renewed 

here use readlines() read file (shown "x.txt"). stri_split_fixed() says want split on space, , want n = 2 columns in return (thereby splitting on first space). simplify = true used return matrix instead of list.

data: x.txt

writelines("liiss license issued limod license modified lipass license assigned (partial assignment) lipnd license assigned (partition/disaggregation) lippnd license issued partial/p&d assignment lipur license purged lirein license reinstated liren license renewed", "x.txt") 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -