I have a .csv file tab delimited. 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). 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.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.