r - 仅标准化数据集中(R)中的一些变量的正确语法是什么?
问题描述
起初我试过:
Bank_sc <- preProcess(x = Bank,
method = c("center", "scale"),
select=c(Age, Experience, Income, Family, CCAvg, Education, Mortgage))
我在这里省略了一个变量,但它仍然是标准化的。我找不到任何关于正确语法的文章,所以请帮忙。
解决方案
您可以使用 dplyr 包
data <- data.frame(x= sample(1:100, 30), y = sample(1:100, 30), z= sample(1:100, 30))
head(data)
x y z
1 26 60 16
2 38 52 51
3 12 25 13
4 32 78 54
5 6 71 59
6 10 83 3
library(dplyr)
data <- data %>% mutate_at(vars(x, y), scale)
head(data)
x y z
1 -0.6630489 0.1550407 16
2 -0.2522096 -0.1088584 51
3 -1.1423613 -0.9995179 13
4 -0.4576293 0.7488137 54
5 -1.3477809 0.5179020 59
6 -1.2108345 0.9137507 3
推荐阅读
- javascript - 使用 jest-image-snapshot 比较图像快照时如何忽略 body 标记中的区域或元素?
- angular - 使用 *ngFor 填充跨 3 个 div 格式化的单选列表
- javafx - JavaFX:需要帮助理解 setControllerFactory
- java - Java/ Talend 根据条件分解字符串并清理数据
- angular - Angular cli 反应形式
- java - Jboss EAP 6 到 EAP 7 升级 - jar 部署失败
- angular - 用数据动态填充 Material Dashboard 组件
- python - 网格几何管理器不会将框架置于窗口中间
- spring - 用于休眠方言 org.hibernate.dialect.Oracle9Dialect 的适当 Oracle 下载
- sql - 如何在 SUM CASE WHEN 语句中将 null 替换为 0?