colMeans中的错误(x,na.rm = TRUE):' x'必须是数字,在这种情况下我该怎么办?

时间:2016-11-23 03:37:40

标签: r

setwd("C:/DSI_Data_HW3")
beach <- read.csv("HW3_Beachtown.csv")
head(beach, 46)
str(beach)

table(beach$SPEOPLE)

summary(beach)
beach_z <- as.data.frame(lapply(beach, scale))

enter image description here

1 个答案:

答案 0 :(得分:3)

正如Roland所指出的那样,你无法对分类变量进行缩放...在你的情况下,将data.frame子集化为具有数值的列会有所帮助。

beach_z <- as.data.frame(apply(beach[c('SPEOPLE','SCAR')], scale))
# or maybe easier...
beach_z <- scale(beach[c('SPEOPLE','SCAR')])