将自定义函数映射到小标题列表中的某些列

时间:2019-10-20 21:21:24

标签: r

我正在尝试应用map来缩放许多列,数据如下:

# A tibble: 20 x 18
   date       ID     var1     var2     Y Y_plus_1    X1    X2    X3    X4     X5      X6     X7      X8       X9    X10
   <date>     <chr> <dbl>    <dbl> <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>   <dbl>  <dbl>   <dbl>    <dbl>  <dbl>
 1 2016-10-28 CAT1   795.  2.52e-5     0        0  4.11    13     0     1 0.0610 4.40e-4 -0.523 -0.753  -1.26e-2 0.170 
 2 2016-10-31 CAT1   785. -1.36e-2     0        0  4.14    12     0     1 0.0704 4.25e-4 -0.125 -0.620  -1.94e-2 0.169 
 3 2016-11-01 CAT1   784. -1.19e-3     1        0  3.98    11     0     1 0.0867 4.17e-4 -0.933 -1.30   -2.05e-2 0.162 
 4 2016-11-02 CAT1   769. -1.90e-2     0        1  6.00    10     0     1 0.0673 4.53e-4 -0.958 -0.793  -1.58e-2 0.159 
 5 2016-11-03 CAT1   762. -8.55e-3     0        0  8.42    10     0     1 0.0877 4.29e-4 -1.51  -1.17   -1.72e-2 0.164 
 6 2016-11-04 CAT1   762. -1.44e-4     1        0  7.95    10     0     1 0.0924 4.26e-4 -1.67  -1.21   -1.46e-2 0.162 
 7 2016-11-07 CAT1   783.  2.69e-2     1        1  7.89    10     0     1 0.0821 4.24e-4 -1.64  -1.06   -1.04e-2 0.161 
 8 2016-11-08 CAT1   791.  1.02e-2     1        1  7.64    10     0     1 0.0361 4.51e-4 -0.963  0.0116 -7.03e-3 0.117 
 9 2016-11-09 CAT1   785. -6.58e-3     1        1  4.51    10     0     1 0.0634 4.87e-4 -0.762  1.15    1.22e-2 0.0745
10 2016-11-10 CAT1   763. -2.90e-2     0        1  4.53    10     0     1 0.0290 5.26e-4 -1.32   0.560   3.11e-2 0.0816
11 2016-11-11 CAT1   754. -1.12e-2     0        0  4.40    10     0     1 0.0404 4.94e-4 -1.74   0.142   4.67e-2 0.120 
12 2016-11-14 CAT1   736. -2.38e-2     0        0  4.19    10     0     1 0.0587 4.93e-4 -2.32  -0.504   6.39e-2 0.121 
13 2016-11-15 CAT1   758.  3.04e-2     1        0  4.27    10     0     1 0.125  4.17e-4 -2.74  -1.19    5.87e-2 0.105 
14 2016-11-16 CAT1   764.  7.90e-3     1        1  2.31    29     0     1 0.0637 3.30e-4 -2.16   0.593  -3.83e-2 0.173 
15 2016-11-17 CAT1   771.  8.83e-3     1        1  2.31    28     0     1 0.0749 3.22e-4 -2.19   1.000   1.74e-2 0.185 
16 2016-11-18 CAT1   761. -1.39e-2     0        1  2.31    27     0     1 0.0828 3.14e-4 -1.70   1.39    8.94e-3 0.181 
17 2016-11-21 CAT1   769.  1.14e-2     1        0  2.31    26     0     1 0.0589 3.24e-4 -2.06   0.798   1.59e-2 0.248 
18 2016-11-22 CAT1   768. -1.21e-3     0        1  2.31    25     0     1 0.0437 3.22e-4 -1.84   0.800  -2.79e-3 0.218 
19 2016-11-23 CAT1   761. -9.48e-3     0        0  2.33    24     0     1 0.0399 3.26e-4 -1.67   0.749   8.74e-4 0.217 
20 2016-11-25 CAT1   762.  9.07e-4     0        0  2.33    23     0     1 0.0536 3.25e-4 -1.90   0.617  -8.00e-4 0.180

我有一个比例函数,我想将其应用于每个列表中的所有X变量。我只是想知道如何将scale函数应用于每个列表中的所有这些列。

功能:

Scale_Me <- function(x){
  (x - mean(x, na.rm = TRUE)) / sd(x, na.rm = TRUE)
}

一个变量的代码:

map(mylist, ~mutate(.x,
               scala = Scale_Me(.x[["var1"]])))

数据:

    mylist <- list(structure(list(date = structure(c(17095, 17098, 17099, 17100, 
17101, 17102, 17105, 17106, 17107, 17108, 17109, 17112, 17113, 
17114, 17115, 17116, 17119, 17120, 17121, 17122), class = "Date"), 
    ID = c("CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", 
    "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", 
    "CAT1", "CAT1", "CAT1", "CAT1", "CAT1"), var1 = c(799.369995, 
    813.109985, 807.669983, 799.070007, 795.349976, 795.369995, 
    784.539978, 783.609985, 768.700012, 762.130005, 762.02002, 
    782.52002, 790.51001, 785.309998, 762.559998, 754.02002, 
    736.080017, 758.48999, 764.47998, 771.22998), var2 = c(0.00301143592272179, 
    0.0171885235697395, -0.00669036428079295, -0.0106478836418512, 
    -0.00465545067066953, 0.0000251700516804565, -0.0136163258207899, 
    -0.00118539912060411, -0.0190272881732103, -0.00854690633203736, 
    -0.000144312649125955, 0.0269021803390415, 0.0102105886057713, 
    -0.00657804700031572, -0.0289694516279417, -0.0111990899370517, 
    -0.0237924756958046, 0.0304450229355975, 0.00789725649510542, 
    0.0088295314155904), Y = c(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 
    1, 1, 1, 1, 0, 0, 0, 1, 1, 1), Y_plus_1 = c(0, 1, 1, 0, 0, 
    0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1), X1 = c(4.13858526513854, 
    4.13858526513855, 4.16341131085939, 4.16341131085937, 4.16341131085937, 
    4.11423119297315, 4.13858526513857, 3.97599968560627, 5.99758130881283, 
    8.41953801047614, 7.95231443679086, 7.88558780320248, 7.6408950559188, 
    4.51370117323327, 4.52868963859669, 4.39998987943623, 4.18852747359839, 
    4.27042958796773, 2.30720560360487, 2.3083029424251), X2 = c(18, 
    17, 16, 15, 14, 13, 12, 11, 10, 10, 10, 10, 10, 10, 10, 10, 
    10, 10, 29, 28), X3 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0), X4 = c(1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), X5 = c(0.0769944316144198, 
    0.0793311568823971, 0.0803743155230278, 0.0625789438826206, 
    0.0586506192715035, 0.0610303101083243, 0.0703939970975855, 
    0.0867098273608016, 0.0673120522212106, 0.0877296725069155, 
    0.0923742675361241, 0.0821050363880187, 0.0360531976099817, 
    0.063410467337928, 0.0289807505667197, 0.0403890038946993, 
    0.0587200889534704, 0.124855015077667, 0.0636602113103218, 
    0.0748772236055617), X6 = c(0.000428660536007568, 0.000424348382531349, 
    0.000403672086504106, 0.000425772306880377, 0.000441567036819891, 
    0.000440420473928468, 0.000424616565866307, 0.000417156794102717, 
    0.000453102696396517, 0.000429420158272163, 0.000426339236438714, 
    0.000424204011080916, 0.000450812884669126, 0.00048728803860348, 
    0.000526461561504051, 0.000494106517096305, 0.000493488610269819, 
    0.00041740609044358, 0.000329604373072286, 0.000321981688032803
    ), X7 = c(0.652246323794644, 0.633658121909502, 0.779640005424855, 
    0.37849713571782, -0.25338461752528, -0.522937755983531, 
    -0.124971717359712, -0.93339126000489, -0.957987757878853, 
    -1.50800507959919, -1.67334654587184, -1.6438607078889, -0.962881285608565, 
    -0.761952591493898, -1.31627449065341, -1.73806924167703, 
    -2.31894300820554, -2.73548173635386, -2.16326733735933, 
    -2.18976199245069), X8 = c(-0.975973892452776, -0.861258722930479, 
    -0.477565916680931, -0.33185021650311, -0.647129621511124, 
    -0.752564004048953, -0.620377457915967, -1.30234931058582, 
    -0.793283548875438, -1.16602371553076, -1.20919980603818, 
    -1.06429334017641, 0.0115994967476536, 1.15288649261686, 
    0.559547871095353, 0.142148842103466, -0.504045772338972, 
    -1.18889934824633, 0.593184249578906, 0.999978721521271), 
    X9 = c(-0.0145637619761308, -0.0147930666936059, -0.0147662947883565, 
    -0.0325177535962596, -0.0128572105783758, -0.0126204141222343, 
    -0.0193506283734377, -0.0204879399440294, -0.015817519858536, 
    -0.0171950326442131, -0.0146419066547099, -0.0104033279055883, 
    -0.00702994914474458, 0.012163515055523, 0.0311052843018782, 
    0.0466972362285693, 0.0638538376999092, 0.0587189119891982, 
    -0.0382761719744182, 0.017369814913167), X10 = c(0.225525775667678, 
    0.218320938251066, 0.205736199627003, 0.18430441198689, 0.171653942908123, 
    0.169720213220954, 0.169160112065287, 0.162051896119269, 
    0.158642308835919, 0.163696353319601, 0.162160340961121, 
    0.160663336867733, 0.116728767616044, 0.0744707092081847, 
    0.0816373143043771, 0.120472162777503, 0.120923040165681, 
    0.10545848677116, 0.172548378854213, 0.184998553367414), 
    X11 = c(0.510204081632653, 0.520408163265306, 0.520408163265306, 
    0.530612244897959, 0.530612244897959, 0.520408163265306, 
    0.520408163265306, 0.520408163265306, 0.530612244897959, 
    0.520408163265306, 0.530612244897959, 0.530612244897959, 
    0.540816326530612, 0.530612244897959, 0.520408163265306, 
    0.530612244897959, 0.530612244897959, 0.530612244897959, 
    0.536082474226804, 0.536082474226804)), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame")), structure(list(
    date = structure(c(17098, 17099, 17100, 17101, 17102, 17105, 
    17106, 17107, 17108, 17109, 17112, 17113, 17114, 17115, 17116, 
    17119, 17120, 17121, 17122, 17123), class = "Date"), ID = c("CAT1", 
    "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", 
    "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", 
    "CAT1", "CAT1", "CAT1"), var1 = c(813.109985, 807.669983, 
    799.070007, 795.349976, 795.369995, 784.539978, 783.609985, 
    768.700012, 762.130005, 762.02002, 782.52002, 790.51001, 
    785.309998, 762.559998, 754.02002, 736.080017, 758.48999, 
    764.47998, 771.22998, 760.539978), var2 = c(0.0171885235697395, 
    -0.00669036428079295, -0.0106478836418512, -0.00465545067066953, 
    0.0000251700516804565, -0.0136163258207899, -0.00118539912060411, 
    -0.0190272881732103, -0.00854690633203736, -0.000144312649125955, 
    0.0269021803390415, 0.0102105886057713, -0.00657804700031572, 
    -0.0289694516279417, -0.0111990899370517, -0.0237924756958046, 
    0.0304450229355975, 0.00789725649510542, 0.0088295314155904, 
    -0.0138609782778413), Y = c(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 
    1, 1, 1, 0, 0, 0, 1, 1, 1, 0), Y_plus_1 = c(1, 1, 0, 0, 0, 
    0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1), X1 = c(4.13858526513855, 
    4.16341131085939, 4.16341131085937, 4.16341131085937, 4.11423119297315, 
    4.13858526513857, 3.97599968560627, 5.99758130881283, 8.41953801047614, 
    7.95231443679086, 7.88558780320248, 7.6408950559188, 4.51370117323327, 
    4.52868963859669, 4.39998987943623, 4.18852747359839, 4.27042958796773, 
    2.30720560360487, 2.3083029424251, 2.3083029424251), X2 = c(17, 
    16, 15, 14, 13, 12, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 
    10, 29, 28, 27), X3 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0), X4 = c(1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), X5 = c(0.0793311568823971, 
    0.0803743155230278, 0.0625789438826206, 0.0586506192715035, 
    0.0610303101083243, 0.0703939970975855, 0.0867098273608016, 
    0.0673120522212106, 0.0877296725069155, 0.0923742675361241, 
    0.0821050363880187, 0.0360531976099817, 0.063410467337928, 
    0.0289807505667197, 0.0403890038946993, 0.0587200889534704, 
    0.124855015077667, 0.0636602113103218, 0.0748772236055617, 
    0.0828248414842617), X6 = c(0.000424348382531349, 0.000403672086504106, 
    0.000425772306880377, 0.000441567036819891, 0.000440420473928468, 
    0.000424616565866307, 0.000417156794102717, 0.000453102696396517, 
    0.000429420158272163, 0.000426339236438714, 0.000424204011080916, 
    0.000450812884669126, 0.00048728803860348, 0.000526461561504051, 
    0.000494106517096305, 0.000493488610269819, 0.00041740609044358, 
    0.000329604373072286, 0.000321981688032803, 0.000313820182149535
    ), X7 = c(0.633658121909502, 0.779640005424855, 0.37849713571782, 
    -0.25338461752528, -0.522937755983531, -0.124971717359712, 
    -0.93339126000489, -0.957987757878853, -1.50800507959919, 
    -1.67334654587184, -1.6438607078889, -0.962881285608565, 
    -0.761952591493898, -1.31627449065341, -1.73806924167703, 
    -2.31894300820554, -2.73548173635386, -2.16326733735933, 
    -2.18976199245069, -1.70174528306041), X8 = c(-0.861258722930479, 
    -0.477565916680931, -0.33185021650311, -0.647129621511124, 
    -0.752564004048953, -0.620377457915967, -1.30234931058582, 
    -0.793283548875438, -1.16602371553076, -1.20919980603818, 
    -1.06429334017641, 0.0115994967476536, 1.15288649261686, 
    0.559547871095353, 0.142148842103466, -0.504045772338972, 
    -1.18889934824633, 0.593184249578906, 0.999978721521271, 
    1.3874173248314), X9 = c(-0.0147930666936059, -0.0147662947883565, 
    -0.0325177535962596, -0.0128572105783758, -0.0126204141222343, 
    -0.0193506283734377, -0.0204879399440294, -0.015817519858536, 
    -0.0171950326442131, -0.0146419066547099, -0.0104033279055883, 
    -0.00702994914474458, 0.012163515055523, 0.0311052843018782, 
    0.0466972362285693, 0.0638538376999092, 0.0587189119891982, 
    -0.0382761719744182, 0.017369814913167, 0.00894072522957917
    ), X10 = c(0.218320938251066, 0.205736199627003, 0.18430441198689, 
    0.171653942908123, 0.169720213220954, 0.169160112065287, 
    0.162051896119269, 0.158642308835919, 0.163696353319601, 
    0.162160340961121, 0.160663336867733, 0.116728767616044, 
    0.0744707092081847, 0.0816373143043771, 0.120472162777503, 
    0.120923040165681, 0.10545848677116, 0.172548378854213, 0.184998553367414, 
    0.181410472295269), X11 = c(0.520408163265306, 0.520408163265306, 
    0.530612244897959, 0.530612244897959, 0.520408163265306, 
    0.520408163265306, 0.520408163265306, 0.530612244897959, 
    0.520408163265306, 0.530612244897959, 0.530612244897959, 
    0.540816326530612, 0.530612244897959, 0.520408163265306, 
    0.530612244897959, 0.530612244897959, 0.530612244897959, 
    0.536082474226804, 0.536082474226804, 0.536082474226804)), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame")), structure(list(
    date = structure(c(17099, 17100, 17101, 17102, 17105, 17106, 
    17107, 17108, 17109, 17112, 17113, 17114, 17115, 17116, 17119, 
    17120, 17121, 17122, 17123, 17126), class = "Date"), ID = c("CAT1", 
    "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", 
    "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", 
    "CAT1", "CAT1", "CAT1"), var1 = c(807.669983, 799.070007, 
    795.349976, 795.369995, 784.539978, 783.609985, 768.700012, 
    762.130005, 762.02002, 782.52002, 790.51001, 785.309998, 
    762.559998, 754.02002, 736.080017, 758.48999, 764.47998, 
    771.22998, 760.539978, 769.200012), var2 = c(-0.00669036428079295, 
    -0.0106478836418512, -0.00465545067066953, 0.0000251700516804565, 
    -0.0136163258207899, -0.00118539912060411, -0.0190272881732103, 
    -0.00854690633203736, -0.000144312649125955, 0.0269021803390415, 
    0.0102105886057713, -0.00657804700031572, -0.0289694516279417, 
    -0.0111990899370517, -0.0237924756958046, 0.0304450229355975, 
    0.00789725649510542, 0.0088295314155904, -0.0138609782778413, 
    0.0113866913646978), Y = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 
    1, 1, 0, 0, 0, 1, 1, 1, 0, 1), Y_plus_1 = c(1, 0, 0, 0, 0, 
    0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0), X1 = c(4.16341131085939, 
    4.16341131085937, 4.16341131085937, 4.11423119297315, 4.13858526513857, 
    3.97599968560627, 5.99758130881283, 8.41953801047614, 7.95231443679086, 
    7.88558780320248, 7.6408950559188, 4.51370117323327, 4.52868963859669, 
    4.39998987943623, 4.18852747359839, 4.27042958796773, 2.30720560360487, 
    2.3083029424251, 2.3083029424251, 2.30720560360488), X2 = c(16, 
    15, 14, 13, 12, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 
    29, 28, 27, 26), X3 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0), X4 = c(1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), X5 = c(0.0803743155230278, 
    0.0625789438826206, 0.0586506192715035, 0.0610303101083243, 
    0.0703939970975855, 0.0867098273608016, 0.0673120522212106, 
    0.0877296725069155, 0.0923742675361241, 0.0821050363880187, 
    0.0360531976099817, 0.063410467337928, 0.0289807505667197, 
    0.0403890038946993, 0.0587200889534704, 0.124855015077667, 
    0.0636602113103218, 0.0748772236055617, 0.0828248414842617, 
    0.0588561607897347), X6 = c(0.000403672086504106, 0.000425772306880377, 
    0.000441567036819891, 0.000440420473928468, 0.000424616565866307, 
    0.000417156794102717, 0.000453102696396517, 0.000429420158272163, 
    0.000426339236438714, 0.000424204011080916, 0.000450812884669126, 
    0.00048728803860348, 0.000526461561504051, 0.000494106517096305, 
    0.000493488610269819, 0.00041740609044358, 0.000329604373072286, 
    0.000321981688032803, 0.000313820182149535, 0.000324018084037671
    ), X7 = c(0.779640005424855, 0.37849713571782, -0.25338461752528, 
    -0.522937755983531, -0.124971717359712, -0.93339126000489, 
    -0.957987757878853, -1.50800507959919, -1.67334654587184, 
    -1.6438607078889, -0.962881285608565, -0.761952591493898, 
    -1.31627449065341, -1.73806924167703, -2.31894300820554, 
    -2.73548173635386, -2.16326733735933, -2.18976199245069, 
    -1.70174528306041, -2.05934220840334), X8 = c(-0.477565916680931, 
    -0.33185021650311, -0.647129621511124, -0.752564004048953, 
    -0.620377457915967, -1.30234931058582, -0.793283548875438, 
    -1.16602371553076, -1.20919980603818, -1.06429334017641, 
    0.0115994967476536, 1.15288649261686, 0.559547871095353, 
    0.142148842103466, -0.504045772338972, -1.18889934824633, 
    0.593184249578906, 0.999978721521271, 1.3874173248314, 0.798117587221041
    ), X9 = c(-0.0147662947883565, -0.0325177535962596, -0.0128572105783758, 
    -0.0126204141222343, -0.0193506283734377, -0.0204879399440294, 
    -0.015817519858536, -0.0171950326442131, -0.0146419066547099, 
    -0.0104033279055883, -0.00702994914474458, 0.012163515055523, 
    0.0311052843018782, 0.0466972362285693, 0.0638538376999092, 
    0.0587189119891982, -0.0382761719744182, 0.017369814913167, 
    0.00894072522957917, 0.0159165549773805), X10 = c(0.205736199627003, 
    0.18430441198689, 0.171653942908123, 0.169720213220954, 0.169160112065287, 
    0.162051896119269, 0.158642308835919, 0.163696353319601, 
    0.162160340961121, 0.160663336867733, 0.116728767616044, 
    0.0744707092081847, 0.0816373143043771, 0.120472162777503, 
    0.120923040165681, 0.10545848677116, 0.172548378854213, 0.184998553367414, 
    0.181410472295269, 0.248454355918383), X11 = c(0.520408163265306, 
    0.530612244897959, 0.530612244897959, 0.520408163265306, 
    0.520408163265306, 0.520408163265306, 0.530612244897959, 
    0.520408163265306, 0.530612244897959, 0.530612244897959, 
    0.540816326530612, 0.530612244897959, 0.520408163265306, 
    0.530612244897959, 0.530612244897959, 0.530612244897959, 
    0.536082474226804, 0.536082474226804, 0.536082474226804, 
    0.530612244897959)), row.names = c(NA, -20L), class = c("tbl_df", 
"tbl", "data.frame")), structure(list(date = structure(c(17100, 
17101, 17102, 17105, 17106, 17107, 17108, 17109, 17112, 17113, 
17114, 17115, 17116, 17119, 17120, 17121, 17122, 17123, 17126, 
17127), class = "Date"), ID = c("CAT1", "CAT1", "CAT1", "CAT1", 
"CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", 
"CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1", "CAT1"
), var1 = c(799.070007, 795.349976, 795.369995, 784.539978, 783.609985, 
768.700012, 762.130005, 762.02002, 782.52002, 790.51001, 785.309998, 
762.559998, 754.02002, 736.080017, 758.48999, 764.47998, 771.22998, 
760.539978, 769.200012, 768.27002), var2 = c(-0.0106478836418512, 
-0.00465545067066953, 0.0000251700516804565, -0.0136163258207899, 
-0.00118539912060411, -0.0190272881732103, -0.00854690633203736, 
-0.000144312649125955, 0.0269021803390415, 0.0102105886057713, 
-0.00657804700031572, -0.0289694516279417, -0.0111990899370517, 
-0.0237924756958046, 0.0304450229355975, 0.00789725649510542, 
0.0088295314155904, -0.0138609782778413, 0.0113866913646978, 
-0.0012090379426567), Y = c(0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 
0, 0, 0, 1, 1, 1, 0, 1, 0), Y_plus_1 = c(0, 0, 0, 0, 0, 1, 0, 
0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1), X1 = c(4.16341131085937, 
4.16341131085937, 4.11423119297315, 4.13858526513857, 3.97599968560627, 
5.99758130881283, 8.41953801047614, 7.95231443679086, 7.88558780320248, 
7.6408950559188, 4.51370117323327, 4.52868963859669, 4.39998987943623, 
4.18852747359839, 4.27042958796773, 2.30720560360487, 2.3083029424251, 
2.3083029424251, 2.30720560360488, 2.30720560360486), X2 = c(15, 
14, 13, 12, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 29, 28, 
27, 26, 25), X3 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0), X4 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1), X5 = c(0.0625789438826206, 0.0586506192715035, 
0.0610303101083243, 0.0703939970975855, 0.0867098273608016, 0.0673120522212106, 
0.0877296725069155, 0.0923742675361241, 0.0821050363880187, 0.0360531976099817, 
0.063410467337928, 0.0289807505667197, 0.0403890038946993, 0.0587200889534704, 
0.124855015077667, 0.0636602113103218, 0.0748772236055617, 0.0828248414842617, 
0.0588561607897347, 0.0437146614571738), X6 = c(0.000425772306880377, 
0.000441567036819891, 0.000440420473928468, 0.000424616565866307, 
0.000417156794102717, 0.000453102696396517, 0.000429420158272163, 
0.000426339236438714, 0.000424204011080916, 0.000450812884669126, 
0.00048728803860348, 0.000526461561504051, 0.000494106517096305, 
0.000493488610269819, 0.00041740609044358, 0.000329604373072286, 
0.000321981688032803, 0.000313820182149535, 0.000324018084037671, 
0.000321928021838835), X7 = c(0.37849713571782, -0.25338461752528, 
-0.522937755983531, -0.124971717359712, -0.93339126000489, -0.957987757878853, 
-1.50800507959919, -1.67334654587184, -1.6438607078889, -0.962881285608565, 
-0.761952591493898, -1.31627449065341, -1.73806924167703, -2.31894300820554, 
-2.73548173635386, -2.16326733735933, -2.18976199245069, -1.70174528306041, 
-2.05934220840334, -1.83997395786783), X8 = c(-0.33185021650311, 
-0.647129621511124, -0.752564004048953, -0.620377457915967, -1.30234931058582, 
-0.793283548875438, -1.16602371553076, -1.20919980603818, -1.06429334017641, 
0.0115994967476536, 1.15288649261686, 0.559547871095353, 0.142148842103466, 
-0.504045772338972, -1.18889934824633, 0.593184249578906, 0.999978721521271, 
1.3874173248314, 0.798117587221041, 0.799993914873595), X9 = c(-0.0325177535962596, 
-0.0128572105783758, -0.0126204141222343, -0.0193506283734377, 
-0.0204879399440294, -0.015817519858536, -0.0171950326442131, 
-0.0146419066547099, -0.0104033279055883, -0.00702994914474458, 
0.012163515055523, 0.0311052843018782, 0.0466972362285693, 0.0638538376999092, 
0.0587189119891982, -0.0382761719744182, 0.017369814913167, 0.00894072522957917, 
0.0159165549773805, -0.00278974160229076), X10 = c(0.18430441198689, 
0.171653942908123, 0.169720213220954, 0.169160112065287, 0.162051896119269, 
0.158642308835919, 0.163696353319601, 0.162160340961121, 0.160663336867733, 
0.116728767616044, 0.0744707092081847, 0.0816373143043771, 0.120472162777503, 
0.120923040165681, 0.10545848677116, 0.172548378854213, 0.184998553367414, 
0.181410472295269, 0.248454355918383, 0.218320516349615), X11 = c(0.530612244897959, 
0.530612244897959, 0.520408163265306, 0.520408163265306, 0.520408163265306, 
0.530612244897959, 0.520408163265306, 0.530612244897959, 0.530612244897959, 
0.540816326530612, 0.530612244897959, 0.520408163265306, 0.530612244897959, 
0.530612244897959, 0.530612244897959, 0.536082474226804, 0.536082474226804, 
0.536082474226804, 0.530612244897959, 0.525773195876289)), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame")))

1 个答案:

答案 0 :(得分:2)

以下方法应该起作用:

mylist %>% 
  map(~ mutate_at(.x, vars(starts_with("X")), Scale_Me))

但是,您在sd = 0上有一些列,其中您的功能无法使用。