简体   繁体   中英

Normalizing Numeric Columns in R

I need to normalize all numeric columns of the data frame clean_mlb.

Here is a picture of clean_mlb (Photo #1)

照片#2

照片 #3

This is the code that I wrote:

scaled_mlb = data.frame(scale(clean_mlb))

And this is the error that I got:

Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric

Find out columns which are numeric and then apply scale on those columns.

cols <- sapply(clean_mlb, is.numeric)
clean_mlb[cols] <- scale(clean_mlb[cols])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM