Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 行结束符号不清楚的表格中的读取问题_R - Fatal编程技术网

R 行结束符号不清楚的表格中的读取问题

R 行结束符号不清楚的表格中的读取问题,r,R,我目前正在尝试读取.txt文件 我在这里进行了研究,发现——然而,这并没有解决我的问题 这些数据是美国联邦选举委员会在 在检查了.txt之后,我意识到数据的结构很奇怪。特别是,任何一行的结尾都和下一行的第一个单元格完全不分开(不是用“|”分隔,也不是用空格分隔) 奇怪的是,通过Excel和Access导入似乎工作得很好。但是,R导入不起作用 为了避免扫描中出现错误(file=file,what=what,sep=sep,quote=quote,dec=dec,:第90行没有27个元素错误,我使用

我目前正在尝试读取.txt文件

我在这里进行了研究,发现——然而,这并没有解决我的问题

这些数据是美国联邦选举委员会在

在检查了.txt之后,我意识到数据的结构很奇怪。特别是,任何一行的结尾都和下一行的第一个单元格完全不分开(不是用“|”分隔,也不是用空格分隔)

奇怪的是,通过Excel和Access导入似乎工作得很好。但是,R导入不起作用

为了避免扫描中出现
错误(file=file,what=what,sep=sep,quote=quote,dec=dec,:第90行没有27个元素
错误,我使用以下命令:

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"))

webk14它可能与变量名中的符号有关,因此请使用
comment.char=”“
来解释这些符号,这将为您提供:

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"))

webk14只需使用
read.delim
instrade of
read.table
。这非常有效-谢谢!