I would like to read a csv file but there are columns that contain strings of digits (string variable). The values in the csv file are quoted (\"\") so easily identifyable as st
You can use as.character()
on your two columns.
Example :
vec <- c(1,2,3)
> vec
[1] 1 2 3
vec <- as.character(vec)
> vec
[1] "1" "2" "3"
So just write :
datSwm[,4:5] <- as.character(datSwm[,4:5])
You could use the read.csv argument: colClasses
colClasses describes the content of the columns (see ?read.csv).
below an example for the first five columns: you need to drop stringAsFactors (it would be overridden by colClasses)
datSwm <- read.csv("datSwm.csv", header=T, quote='\"',
colClasses = c("factor", "numeric", "character", "character", "character") )
You will need to add more details for the remaining columns.
Try this :
datSwm <- read.csv("datSwm.csv", header=T, stringsAsFactors=FALSE, quote='\"',colClasses=c("character","numeric","character","character","character","numeric","character","character","character","numeric","numeric"))