At the moment I am reading in a data file like this:
setwd("N:/HH Scallop Growth Project/Ring data by cruise/")
growth <- read.csv("Growth.csv",sep=",",header=TRUE,
colClasses=c("character","character","character","numeric",
"character","numeric","numeric","numeric",
"numeric","numeric","numeric","numeric",
"numeric","numeric","character","numeric",
"character","numeric","numeric","numeric",
"numeric","character","numeric","numeric",
"numeric"))
It works fine but it is a bit long/scruffy, is there a way of shortening/grouping the colClasses
?
Try creating a 25-vector whose entries are all "numeric"
and then just replace the few that are not with "character"
. Also note that header=TRUE
and sep=","
are the default for read.csv
so they can be omitted.
colClasses <- replace(rep("numeric", 25), c(1:3, 5, 15, 17, 22), "character")
growth <- read.csv("Growth.csv", colClasses = colClasses)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With