import - R read.csv "More columns than column names" error -
i have problem when importing .csv
file r. code:
t <- read.csv("c:\\n0_07312014.csv", na.string=c("","null","nan","x"), header=t, stringsasfactors=false,check.names=f)
r reports error , not want:
error in read.table(file = file, header = header, sep = sep, quote = quote, : more columns column names
i guess problem because data not formatted. need data [,1:32]
. others should deleted.
data can downloaded from: https://drive.google.com/file/d/0b86_a8ltyol3vxjym3nvdmnpmuu/edit?usp=sharing
thanks much!
that's 1 wonky csv file. multiple headers tossed (try pasting csv fingerprint) see mean.
since don't know data, it's impossible sure following produces accurate results you, involves using readlines
, other r functions pre-process text:
# use readlines data dat <- readlines("n0_07312014.csv") # had fix grep errors sys.setlocale('lc_all','c') # filter out repeating, , wonky headers dat_2 <- grep("node name,rtc_date", dat, invert=true, value=true) # turn vector text connection read.csv dat_3 <- read.csv(textconnection(paste0(dat_2, collapse="\n")), header=false, stringsasfactors=false) str(dat_3) ## 'data.frame': 308 obs. of 37 variables: ## $ v1 : chr "node 0" "node 0" "node 0" "node 0" ... ## $ v2 : chr "07/31/2014" "07/31/2014" "07/31/2014" "07/31/2014" ... ## $ v3 : chr "08:58:18" "08:59:22" "08:59:37" "09:00:06" ... ## $ v4 : chr "" "" "" "" ... ## .. more ## $ v36: chr "" "" "" "" ... ## $ v37: chr "0" "0" "0" "0" ... # grab headers headers <- strsplit(dat[1], ",")[[1]] # how many of them there? length(headers) ## [1] 32 # limit 32 columns want (which matches) dat_4 <- dat_3[,1:32] # , add headers colnames(dat_4) <- headers str(dat_4) ## 'data.frame': 308 obs. of 32 variables: ## $ node name : chr "node 0" "node 0" "node 0" "node 0" ... ## $ rtc_date : chr "07/31/2014" "07/31/2014" "07/31/2014" "07/31/2014" ... ## $ rtc_time : chr "08:58:18" "08:59:22" "08:59:37" "09:00:06" ... ## $ n1 bat (vdc) : chr "" "" "" "" ... ## $ n1 shinyei (ug/m3): chr "" "" "0.23" "null" ... ## $ n1 cc (ppb) : chr "" "" "null" "null" ... ## $ n1 aeroq (ppm) : chr "" "" "null" "null" ... ## ... continues
Comments
Post a Comment