I have this data frame and I would like to rename the column name inside the loop, but it doesn't do what I want.
list_prices_python[[1]]
DATE Instrument TR.CLOSEPRICE
<date> <chr> <dbl>
1 2009-01-01 NA 356.
2 2009-01-02 NA 356.
3 2009-01-03 NA 356.
4 2009-01-04 NA 357.
5 2009-01-05 NA 357.
6 2009-01-06 NA 357.
7 2009-01-07 NA 357.
8 2009-01-08 NA 357.
9 2009-01-09 NA 357.
10 2009-01-10 NA 357.
name_prices_python
[1] "ASF.CN" "CAR_p.CN" "CIC.CN" "CLM.CN" "CON.CN" "CTV.CN" "DVI_p.CN" "FGN.CN"
"GNO.CN" "MYG.CN"
[11] "ORB.CN" "PMG.CN" "RPI.CN" "TPL.CN" "TRR.CN"
for(i in name_prices_python){
list_prices_python[[i]] %>%
dplyr::rename(i = `TR.CLOSEPRICE`) -> list_prices_python[[i]]
}
The output is each column named "i". Not what I expected.
# A tibble: 4,944 x 3
DATE Instrument i
<date> <chr> <dbl>
1 2009-01-01 NA 356.
2 2009-01-02 NA 356.
3 2009-01-03 NA 356.
4 2009-01-04 NA 357.
5 2009-01-05 NA 357.
6 2009-01-06 NA 357.
7 2009-01-07 NA 357.
8 2009-01-08 NA 357.
9 2009-01-09 NA 357.
10 2009-01-10 NA 357.
What should I modify? Thank you.
Created on 2022-07-15 by the reprex package (v2.0.1)