[英]Tab - delimited .csv file into R
I have a .csv file tab delimited. 我有一个.csv文件标签定界。 While running the code
在运行代码时
data <- read.table("xxx.csv",sep = "\t", dec=".", header = TRUE,
encoding="UTF-8", stringsAsFactors = FALSE)
R reads it as a single column without dividing (should make 42 columns). R将其读取为单列而不进行除法(应为42列)。 Any ideas?
有任何想法吗? Link to file .
链接到文件 。
The problem arises because each line is between quotation marks (the whole line). 出现问题是因为每一行都在引号(整行)之间。
There are two possible ways to read the file. 有两种可能的方式来读取文件。
Keep all quotation marks. 保留所有引号。
Use the parameter quote = ""
to disable quoting. 使用参数
quote = ""
禁用引用。
read.table("xxx.csv", sep = "\\t", dec = ".", header = TRUE, encoding = "UTF-8", stringsAsFactors = FALSE, quote = "")
Remove the quotation marks before reading the file. 在读取文件之前,请删除引号。
tmp <- gsub('^\\"|\\"$', '', readLines("xxx.csv")) read.table(text = tmp, sep = "\\t", dec = ".", header = TRUE, encoding = "UTF-8", stringsAsFactors = FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.