简体   繁体   English

标准化 R 中的数字列

[英]Normalizing Numeric Columns in R

I need to normalize all numeric columns of the data frame clean_mlb.我需要规范化数据框 clean_mlb 的所有数字列。

Here is a picture of clean_mlb (Photo #1)这是 clean_mlb 的图片(照片 #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 colMeans(x, na.rm = TRUE) 中的错误:“x”必须是数字

Find out columns which are numeric and then apply scale on those columns.找出数字列,然后在这些列上应用scale

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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