r - Importing multi space delimited file -
good day,
i'm trying import data text file r. formatted data no issue, when delimiter double/triple space?
for example have following data in text format
var1 var2 var3 30000 sedan model 2014 30000 chevrolet corvette stingray ....
in instead of \t (tab) delimited 3 space ( ) delimited. data in column may contain single spaces.
how make r accept directly?
i've tried read.table, separator identifier (sep="") not seem accept multiple characters , regular expressions not supported. (as far know.) seems work read data in tab delimited , splitting once it's in dataframe, silly.
you can use tidyr::separate
split data columns 3 spaces.
df <- read.table(text = "var1 var2 var3 30000 sedan model 2014 30000 chevrolet corvette stingray", sep = "%", skip = 1) tidyr::separate(df, v1, c("var1", "var2", "var3"), sep = "\\s{3}", ) var1 var2 var3 1 30000 sedan model 2014 2 30000 chevrolet corvette stingray
Comments
Post a Comment