r - Problems reading in table with unclear line-end symbol -
i trying read in .txt file.
i have researched here , found error in reading in data set in r - however, did not solve problem.
the data political contributions listed federal election commission of u.s. @ ftp://ftp.fec.gov/fec/2014/webk14.zip
upon inspection of .txt, realized data weirdly structured. especially, end of line not separated @ first cell of next line (not "|", not space).
strangely enough, import via excel , access seems work fine. however, r import not work.
to avoid error in scan(file = file, = what, sep = sep, quote = quote, dec = dec, : line 90 did not have 27 elements error, use following command:
webk14 <- read.table(header = false, fill = true, colclasses = "character", sep = "|", file = "webk14.txt", stringsasfactors = false, dec = ".", col.names = c("cmte_id", "cmte_nm", "cmte_tp", "cmte_dsgn", "cmte_filing_freq", "ttl_receipts", "trans_from_aff", "indv_contrib", "other_pol_cmte_contrib", "cand_contrib", "cand_loans", "ttl_loans_received", "ttl_disb", "tranf_to_aff", "indv_refunds", "other_pol_cmte_refunds", "cand_loan_repay", "loan_repay", "coh_bop", "coh_cop", "debts_owed_by", "nonfed_trans_received", "contrib_to_other_cmte", "ind_exp", "pty_coord_exp", "nonfed_share_exp","cvg_end_dt")) this not result in error, however, results a) have different line count excel import , b) fail correctly separate columns (which reason a))
i not detour via excel , directly import r. ideas doing wrong?
it might related symbols inside variable names turn of interpretation of these using comment.char="", gives you:
webk14 <- read.table(header = false, fill = true, colclasses = "character", comment.char="",sep = "|",file = "webk14.txt", stringsasfactors = false, dec = ".", col.names = c("cmte_id", "cmte_nm", "cmte_tp", "cmte_dsgn", "cmte_filing_freq", "ttl_receipts", "trans_from_aff", "indv_contrib", "other_pol_cmte_contrib", "cand_contrib", "cand_loans", "ttl_loans_received", "ttl_disb", "tranf_to_aff", "indv_refunds", "other_pol_cmte_refunds", "cand_loan_repay", "loan_repay", "coh_bop", "coh_cop", "debts_owed_by", "nonfed_trans_received", "contrib_to_other_cmte", "ind_exp", "pty_coord_exp", "nonfed_share_exp","cvg_end_dt"))
Comments
Post a Comment