目前,我正在读取这样的数据文件:
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"))
它可以正常工作,但有点长/s,是否可以缩短/分组
colClasses
? 最佳答案
尝试创建一个25个向量,其所有条目均为"numeric"
,然后仅用"character"
替换一些不包含在内的矢量。另请注意,header=TRUE
和sep=","
是read.csv
的默认设置,因此可以省略。
colClasses <- replace(rep("numeric", 25), c(1:3, 5, 15, 17, 22), "character")
growth <- read.csv("Growth.csv", colClasses = colClasses)
关于r - 有没有办法缩短一系列colClasses,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23936965/