Is there a way to shorten a series of colClasses

r

Solution

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)

Problem

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`?

Original source