r - Error in read.fwf when header=TRUE -
i have simulated data looks this:
lastname date email creditcardnum agezip amount paul 21/02/14 aliquam.fringilla@dolordapibus.co.uk 4241033422900360 6738851$14.39 bullock 2/7/2014adipiscing.fringilla@lectusjusto.org 5178789953524240 3336538$498.31 mcmahon 11/5/2013lobortis.ultrices@lacus.org 5389589582467450 7734302$92.44 walters 25/09/13 consectetuer.cursus.et@sitamet.org 5157094536097720 7794007$206.60 franco 17/06/13 et@disparturientmontes.ca 345477952996264 2415873$89.12
and how i'm attempting import r, headers:
w <- c(11,10,57,16,3,5,8) df <- read.fwf("data.txt",widths=w,stringsasfactors=f) names(df) <- df[1,]; df <- df[-1,]
the reason i'm not using header=t
gives me error:
error in read.table(file = file, header = header, sep = sep, row.names = row.names, : more columns column names
which isn't true. know widths (w
) correct. error coming from? solution works fine, i'd understand what's happening.
if specify header=true
, then, per ?read.fwf
, must ensure column names separated sep
. default names separated \t
(the tab character) , must not true data.
the following works fine:
w <- c(11, 10, 57, 16, 3, 5, 8) read.fwf(widths=w, header=true, sep='|', file=textconnection('lastname |date |email |creditcardnum |age|zip |amount paul 21/02/14 aliquam.fringilla@dolordapibus.co.uk 4241033422900360 6738851$14.39 bullock 2/7/2014adipiscing.fringilla@lectusjusto.org 5178789953524240 3336538$498.31 mcmahon 11/5/2013lobortis.ultrices@lacus.org 5389589582467450 7734302$92.44 walters 25/09/13 consectetuer.cursus.et@sitamet.org 5157094536097720 7794007$206.60 franco 17/06/13 et@disparturientmontes.ca 345477952996264 2415873$89.12'))
Comments
Post a Comment