dataframe - How to split columns in data frame by semicolon in R -
my question feels me obvious, however, not find solution.
a have data frame this:
<ticker>;<per>;<date>;<time>;<open>;<high>;<low>;<close> usd index;d;20150801;000000;97.199;97.336;97.191;97.192 usd index;d;20150802;000000;97.226;97.294;97.207;97.257 usd index;d;20150803;000000;97.255;97.582;97.155;97.499
i need them split in different columns ; this:
<ticker> <per> <date> <time> <open> <high> <low> <close> usd index d 20150801 0 97.199 97.336 97.191 97.192 usd index d 20150802 0 97.226 97.294 97.207 97.257 usd index d 20150803 0 97.255 97.582 97.155 97.499
this basic question needs @ top of search results. thank in advance helping me resolve issue!
we can use read.table
setnames(read.table(text=dat[,1], sep=";", stringsasfactors=false), scan(text=names(dat), sep=";", = "", quiet = true)) # <ticker> <per> <date> <time> <open> <high> <low> <close> # 1 usd index d 20150801 0 97.199 97.336 97.191 97.192 # 2 usd index d 20150802 0 97.226 97.294 97.207 97.257 # 3 usd index d 20150803 0 97.255 97.582 97.155 97.499
data
dat <- structure(list(`<ticker>;<per>;<date>;<time>;<open>;<high>;<low>;<close>` = c("usd index;d;20150801;000000;97.199;97.336;97.191;97.192", "usd index;d;20150802;000000;97.226;97.294;97.207;97.257", "usd index;d;20150803;000000;97.255;97.582;97.155;97.499" )), .names = "<ticker>;<per>;<date>;<time>;<open>;<high>;<low>;<close>", class = "data.frame", row.names = c(na, -3l))
Comments
Post a Comment