我正在尝试Winsorize()
使用包中lapply
的功能library(DescTools)
。我目前拥有的是;
data$col1 <- Winsorize(data$col1)
它本质上用基于分位数的值替换了极值,替换以下数据如下;
> data$col1
[1] -0.06775798 **-0.55213508** -0.12338265
[4] 0.04928349 **0.47524313** 0.04782829
[7] -0.05070639 **-112.67126382** 0.12657896
[10] -0.12886632
> Winsorize(data$col1)
[1] -0.06775798 **-0.37884540** -0.12338265 0.04928349
[5] **0.26038103** 0.04782829 -0.05070639 **-0.37884540**
[9] 0.12657896 -0.12886632
我有一个可以在 data.frame 、、、for loop
的所有列中执行此操作的方法,但是,我知道这是一个更好的选择,因此我尝试将其合并到一个函数中,但似乎无法使其正常工作。如果有人能指出我正确的方向,那将不胜感激。col1
col2
col3
col4
lapply
lapply
数据;
data <- structure(list(EQ.TA = c(-0.0677579847115102, -0.552135083517749,
-0.123382654164705, 0.0492834931482554, 0.475243125304193, 0.0478282913638668,
-0.050706389027946, -112.671263815473, 0.126578956975704, -0.128866322940619
), NI.EQ = c(3.64670235329765, 1.66115713369585, 0.209424623633739,
0.340430636358184, -0.248411254566261, -12.1709277350516, 1.06888235737433,
0.0515582237132515, 0.177323118521857, 0.419879195374698), NI.TA = c(-0.24709320230217,
-0.917183132749265, -0.0258393659113752, 0.0167776109344148,
-0.118055740980805, -0.582114677880617, -0.0541991646381309,
-5.80913022585296, 0.0224453753901758, -0.0541082879872031),
TL.TA = c(1.06775798471151, 1.55213508351775, 1.12338265416471,
0.950716506851745, 0.524756874695807, 0.952171708636133,
1.05070638902795, 113.671263815473, 0.873421043024296, 1.12886632294062
)), .Names = c("EQ.TA", "NI.EQ", "NI.TA", "TL.TA"), row.names = c(NA,
10L), class = "data.frame")