Home > Enterprise >  Rename names of named vectors in a list according to pattern
Rename names of named vectors in a list according to pattern

Time:08-25

I am trying to rename the names of a named numerical vector within a list, by adding "_M" at the end of the name when the name contains "F0".

The data is stored inside a list, which also holds six lists. Within those six lists there are several numerics with names. Some of them contain the the pattern "F0" in their name. To the name of those elements I want to add "_M". For example "VA01_F0finEnv_sma" should look like this "VA01_F0finEnv_sma_M". These patterns can be found in all of the six lists. Below you can find how the data looks like and also my attempt on renaming the names.

This is the data's dput(zF_10_agg_m):

list(VA01.000252 = 

c(VA01_F0finEnv_sma = 0.149095349677244, VA01_F0final_sma = 0.120929343088889, 
    VA01_jitterLocal_sma = -0.0785745451433892, VA01_shimmerLocal_sma = -0.114102345203172, 
    VA01_mfcc_sma.0. = -0.0642286999362642, VA01_mfcc_sma.1. = -0.030206778340382, 
    VA01_mfcc_sma.2. = -0.208549388306997, VA01_mfcc_sma.3. = -0.192020923835602, 
    VA01_mfcc_sma.4. = -0.0370518353007777, VA01_mfcc_sma.5. = -0.093751840248999, 
    VA01_mfcc_sma.6. = 0.0721460591859715, VA01_mfcc_sma.7. = -0.143256107040908, 
    VA01_mfcc_sma.8. = -0.0794306655354017, VA01_mfcc_sma.9. = -0.244959943019604, 
    VA01_mfcc_sma.10. = -0.0774633729052873, VA01_mfcc_sma.11. = 0.00797079006761165, 
    VA01_mfcc_sma.12. = -0.218709025578709, VA01_mfcc_sma.13. = -0.230465062187873, 
    VA01_mfcc_sma.14. = -0.166280574763084, VA02_F0finEnv_sma = NA, 
    VA02_F0final_sma = NA, VA02_jitterLocal_sma = NA, VA02_shimmerLocal_sma = NA, 
    VA02_mfcc_sma.0. = NA, VA02_mfcc_sma.1. = NA, VA02_mfcc_sma.2. = NA, 
    VA02_mfcc_sma.3. = NA, VA02_mfcc_sma.4. = NA, VA02_mfcc_sma.5. = NA, 
    VA02_mfcc_sma.6. = NA, VA02_mfcc_sma.7. = NA, VA02_mfcc_sma.8. = NA, 
    VA02_mfcc_sma.9. = NA, VA02_mfcc_sma.10. = NA, VA02_mfcc_sma.11. = NA, 
    VA02_mfcc_sma.12. = NA, VA02_mfcc_sma.13. = NA, VA02_mfcc_sma.14. = NA, 
    VA03_F0finEnv_sma = NA, VA03_F0final_sma = NA, VA03_jitterLocal_sma = NA, 
    VA03_shimmerLocal_sma = NA, VA03_mfcc_sma.0. = NA, VA03_mfcc_sma.1. = NA, 
    VA03_mfcc_sma.2. = NA, VA03_mfcc_sma.3. = NA, VA03_mfcc_sma.4. = NA, 
    VA03_mfcc_sma.5. = NA, VA03_mfcc_sma.6. = NA, VA03_mfcc_sma.7. = NA, 
    VA03_mfcc_sma.8. = NA, VA03_mfcc_sma.9. = NA, VA03_mfcc_sma.10. = NA, 
    VA03_mfcc_sma.11. = NA, VA03_mfcc_sma.12. = NA, VA03_mfcc_sma.13. = NA, 
    VA03_mfcc_sma.14. = NA, VB01_F0finEnv_sma = NA, VB01_F0final_sma = NA, 
    VB01_jitterLocal_sma = NA, VB01_shimmerLocal_sma = NA, VB01_mfcc_sma.0. = NA, 
    VB01_mfcc_sma.1. = NA, VB01_mfcc_sma.2. = NA, VB01_mfcc_sma.3. = NA, 
    VB01_mfcc_sma.4. = NA, VB01_mfcc_sma.5. = NA, VB01_mfcc_sma.6. = NA, 
    VB01_mfcc_sma.7. = NA, VB01_mfcc_sma.8. = NA, VB01_mfcc_sma.9. = NA, 
    VB01_mfcc_sma.10. = NA, VB01_mfcc_sma.11. = NA, VB01_mfcc_sma.12. = NA, 
    VB01_mfcc_sma.13. = NA, VB01_mfcc_sma.14. = NA), 

VA01.000306 = c(VA01_F0finEnv_sma = -0.265406298807794, 
    VA01_F0final_sma = -0.217207612472567, VA01_jitterLocal_sma = 0.150860347120316, 
    VA01_shimmerLocal_sma = 0.210465396713397, VA01_mfcc_sma.0. = 0.114340766331976, 
    VA01_mfcc_sma.1. = 0.0537744993637855, VA01_mfcc_sma.2. = 0.371262331337075, 
    VA01_mfcc_sma.3. = 0.341838144083938, VA01_mfcc_sma.4. = 0.065960158721897, 
    VA01_mfcc_sma.5. = 0.166898244394498, VA01_mfcc_sma.6. = -0.128435352160981, 
    VA01_mfcc_sma.7. = 0.255026383486623, VA01_mfcc_sma.8. = 0.141403503053762, 
    VA01_mfcc_sma.9. = 0.436080874021934, VA01_mfcc_sma.10. = 0.137901303147026, 
    VA01_mfcc_sma.11. = -0.0141897040654165, VA01_mfcc_sma.12. = 0.389348649641122, 
    VA01_mfcc_sma.13. = 0.41027689879224, VA01_mfcc_sma.14. = 0.296014840147772, 
    VA02_F0finEnv_sma = NA, VA02_F0final_sma = NA, VA02_jitterLocal_sma = NA, 
    VA02_shimmerLocal_sma = NA, VA02_mfcc_sma.0. = NA, VA02_mfcc_sma.1. = NA, 
    VA02_mfcc_sma.2. = NA, VA02_mfcc_sma.3. = NA, VA02_mfcc_sma.4. = NA, 
    VA02_mfcc_sma.5. = NA, VA02_mfcc_sma.6. = NA, VA02_mfcc_sma.7. = NA, 
    VA02_mfcc_sma.8. = NA, VA02_mfcc_sma.9. = NA, VA02_mfcc_sma.10. = NA, 
    VA02_mfcc_sma.11. = NA, VA02_mfcc_sma.12. = NA, VA02_mfcc_sma.13. = NA, 
    VA02_mfcc_sma.14. = NA, VA03_F0finEnv_sma = NA, VA03_F0final_sma = NA, 
    VA03_jitterLocal_sma = NA, VA03_shimmerLocal_sma = NA, VA03_mfcc_sma.0. = NA, 
    VA03_mfcc_sma.1. = NA, VA03_mfcc_sma.2. = NA, VA03_mfcc_sma.3. = NA, 
    VA03_mfcc_sma.4. = NA, VA03_mfcc_sma.5. = NA, VA03_mfcc_sma.6. = NA, 
    VA03_mfcc_sma.7. = NA, VA03_mfcc_sma.8. = NA, VA03_mfcc_sma.9. = NA, 
    VA03_mfcc_sma.10. = NA, VA03_mfcc_sma.11. = NA, VA03_mfcc_sma.12. = NA, 
    VA03_mfcc_sma.13. = NA, VA03_mfcc_sma.14. = NA, VB01_F0finEnv_sma = NA, 
    VB01_F0final_sma = NA, VB01_jitterLocal_sma = NA, VB01_shimmerLocal_sma = NA, 
    VB01_mfcc_sma.0. = NA, VB01_mfcc_sma.1. = NA, VB01_mfcc_sma.2. = NA, 
    VB01_mfcc_sma.3. = NA, VB01_mfcc_sma.4. = NA, VB01_mfcc_sma.5. = NA, 
    VB01_mfcc_sma.6. = NA, VB01_mfcc_sma.7. = NA, VB01_mfcc_sma.8. = NA, 
    VB01_mfcc_sma.9. = NA, VB01_mfcc_sma.10. = NA, VB01_mfcc_sma.11. = NA, 
    VB01_mfcc_sma.12. = NA, VB01_mfcc_sma.13. = NA, VB01_mfcc_sma.14. = NA
    ), 

VA01.000371 = c(VA01_F0finEnv_sma = 0.149095349677244, VA01_F0final_sma = 0.120929343088889, 
    VA01_jitterLocal_sma = -0.0785745451433892, VA01_shimmerLocal_sma = -0.114102345203172, 
    VA01_mfcc_sma.0. = -0.0642286999362642, VA01_mfcc_sma.1. = -0.030206778340382, 
    VA01_mfcc_sma.2. = -0.208549388306997, VA01_mfcc_sma.3. = -0.192020923835602, 
    VA01_mfcc_sma.4. = -0.0370518353007777, VA01_mfcc_sma.5. = -0.093751840248999, 
    VA01_mfcc_sma.6. = 0.0721460591859715, VA01_mfcc_sma.7. = -0.143256107040908, 
    VA01_mfcc_sma.8. = -0.0794306655354017, VA01_mfcc_sma.9. = -0.244959943019604, 
    VA01_mfcc_sma.10. = -0.0774633729052873, VA01_mfcc_sma.11. = 0.00797079006761165, 
    VA01_mfcc_sma.12. = -0.218709025578709, VA01_mfcc_sma.13. = -0.230465062187873, 
    VA01_mfcc_sma.14. = -0.166280574763084, VA02_F0finEnv_sma = NA, 
    VA02_F0final_sma = NA, VA02_jitterLocal_sma = NA, VA02_shimmerLocal_sma = NA, 
    VA02_mfcc_sma.0. = NA, VA02_mfcc_sma.1. = NA, VA02_mfcc_sma.2. = NA, 
    VA02_mfcc_sma.3. = NA, VA02_mfcc_sma.4. = NA, VA02_mfcc_sma.5. = NA, 
    VA02_mfcc_sma.6. = NA, VA02_mfcc_sma.7. = NA, VA02_mfcc_sma.8. = NA, 
    VA02_mfcc_sma.9. = NA, VA02_mfcc_sma.10. = NA, VA02_mfcc_sma.11. = NA, 
    VA02_mfcc_sma.12. = NA, VA02_mfcc_sma.13. = NA, VA02_mfcc_sma.14. = NA, 
    VA03_F0finEnv_sma = NA, VA03_F0final_sma = NA, VA03_jitterLocal_sma = NA, 
    VA03_shimmerLocal_sma = NA, VA03_mfcc_sma.0. = NA, VA03_mfcc_sma.1. = NA, 
    VA03_mfcc_sma.2. = NA, VA03_mfcc_sma.3. = NA, VA03_mfcc_sma.4. = NA, 
    VA03_mfcc_sma.5. = NA, VA03_mfcc_sma.6. = NA, VA03_mfcc_sma.7. = NA, 
    VA03_mfcc_sma.8. = NA, VA03_mfcc_sma.9. = NA, VA03_mfcc_sma.10. = NA, 
    VA03_mfcc_sma.11. = NA, VA03_mfcc_sma.12. = NA, VA03_mfcc_sma.13. = NA, 
    VA03_mfcc_sma.14. = NA, VB01_F0finEnv_sma = NA, VB01_F0final_sma = NA, 
    VB01_jitterLocal_sma = NA, VB01_shimmerLocal_sma = NA, VB01_mfcc_sma.0. = NA, 
    VB01_mfcc_sma.1. = NA, VB01_mfcc_sma.2. = NA, VB01_mfcc_sma.3. = NA, 
    VB01_mfcc_sma.4. = NA, VB01_mfcc_sma.5. = NA, VB01_mfcc_sma.6. = NA, 
    VB01_mfcc_sma.7. = NA, VB01_mfcc_sma.8. = NA, VB01_mfcc_sma.9. = NA, 
    VB01_mfcc_sma.10. = NA, VB01_mfcc_sma.11. = NA, VB01_mfcc_sma.12. = NA, 
    VB01_mfcc_sma.13. = NA, VB01_mfcc_sma.14. = NA), 

VA02.000371 = c(VA01_F0finEnv_sma = NA, 
    VA01_F0final_sma = NA, VA01_jitterLocal_sma = NA, VA01_shimmerLocal_sma = NA, 
    VA01_mfcc_sma.0. = NA, VA01_mfcc_sma.1. = NA, VA01_mfcc_sma.2. = NA, 
    VA01_mfcc_sma.3. = NA, VA01_mfcc_sma.4. = NA, VA01_mfcc_sma.5. = NA, 
    VA01_mfcc_sma.6. = NA, VA01_mfcc_sma.7. = NA, VA01_mfcc_sma.8. = NA, 
    VA01_mfcc_sma.9. = NA, VA01_mfcc_sma.10. = NA, VA01_mfcc_sma.11. = NA, 
    VA01_mfcc_sma.12. = NA, VA01_mfcc_sma.13. = NA, VA01_mfcc_sma.14. = NA, 
    VA02_F0finEnv_sma = 1.85127192814681e-16, VA02_F0final_sma = -5.00994289546507e-17, 
    VA02_jitterLocal_sma = -2.34859079707077e-17, VA02_shimmerLocal_sma = -2.60455164544764e-17, 
    VA02_mfcc_sma.0. = -2.39198962485355e-17, VA02_mfcc_sma.1. = -3.89002856985193e-17, 
    VA02_mfcc_sma.2. = -2.78570899311261e-17, VA02_mfcc_sma.3. = 2.68372615000544e-17, 
    VA02_mfcc_sma.4. = -2.08322992987213e-17, VA02_mfcc_sma.5. = 5.73790146364059e-18, 
    VA02_mfcc_sma.6. = -2.27766888801672e-17, VA02_mfcc_sma.7. = 3.11227273727354e-17, 
    VA02_mfcc_sma.8. = -2.45352291763184e-18, VA02_mfcc_sma.9. = -5.66246851843269e-17, 
    VA02_mfcc_sma.10. = 2.26611187363704e-17, VA02_mfcc_sma.11. = 1.36185358636217e-18, 
    VA02_mfcc_sma.12. = 1.13196270572855e-17, VA02_mfcc_sma.13. = -4.09118309040634e-17, 
    VA02_mfcc_sma.14. = 8.56156119316215e-18, VA03_F0finEnv_sma = NA, 
    VA03_F0final_sma = NA, VA03_jitterLocal_sma = NA, VA03_shimmerLocal_sma = NA, 
    VA03_mfcc_sma.0. = NA, VA03_mfcc_sma.1. = NA, VA03_mfcc_sma.2. = NA, 
    VA03_mfcc_sma.3. = NA, VA03_mfcc_sma.4. = NA, VA03_mfcc_sma.5. = NA, 
    VA03_mfcc_sma.6. = NA, VA03_mfcc_sma.7. = NA, VA03_mfcc_sma.8. = NA, 
    VA03_mfcc_sma.9. = NA, VA03_mfcc_sma.10. = NA, VA03_mfcc_sma.11. = NA, 
    VA03_mfcc_sma.12. = NA, VA03_mfcc_sma.13. = NA, VA03_mfcc_sma.14. = NA, 
    VB01_F0finEnv_sma = NA, VB01_F0final_sma = NA, VB01_jitterLocal_sma = NA, 
    VB01_shimmerLocal_sma = NA, VB01_mfcc_sma.0. = NA, VB01_mfcc_sma.1. = NA, 
    VB01_mfcc_sma.2. = NA, VB01_mfcc_sma.3. = NA, VB01_mfcc_sma.4. = NA, 
    VB01_mfcc_sma.5. = NA, VB01_mfcc_sma.6. = NA, VB01_mfcc_sma.7. = NA, 
    VB01_mfcc_sma.8. = NA, VB01_mfcc_sma.9. = NA, VB01_mfcc_sma.10. = NA, 
    VB01_mfcc_sma.11. = NA, VB01_mfcc_sma.12. = NA, VB01_mfcc_sma.13. = NA, 
    VB01_mfcc_sma.14. = NA), 

VA03.000389 = c(VA01_F0finEnv_sma = NA, 
    VA01_F0final_sma = NA, VA01_jitterLocal_sma = NA, VA01_shimmerLocal_sma = NA, 
    VA01_mfcc_sma.0. = NA, VA01_mfcc_sma.1. = NA, VA01_mfcc_sma.2. = NA, 
    VA01_mfcc_sma.3. = NA, VA01_mfcc_sma.4. = NA, VA01_mfcc_sma.5. = NA, 
    VA01_mfcc_sma.6. = NA, VA01_mfcc_sma.7. = NA, VA01_mfcc_sma.8. = NA, 
    VA01_mfcc_sma.9. = NA, VA01_mfcc_sma.10. = NA, VA01_mfcc_sma.11. = NA, 
    VA01_mfcc_sma.12. = NA, VA01_mfcc_sma.13. = NA, VA01_mfcc_sma.14. = NA, 
    VA02_F0finEnv_sma = NA, VA02_F0final_sma = NA, VA02_jitterLocal_sma = NA, 
    VA02_shimmerLocal_sma = NA, VA02_mfcc_sma.0. = NA, VA02_mfcc_sma.1. = NA, 
    VA02_mfcc_sma.2. = NA, VA02_mfcc_sma.3. = NA, VA02_mfcc_sma.4. = NA, 
    VA02_mfcc_sma.5. = NA, VA02_mfcc_sma.6. = NA, VA02_mfcc_sma.7. = NA, 
    VA02_mfcc_sma.8. = NA, VA02_mfcc_sma.9. = NA, VA02_mfcc_sma.10. = NA, 
    VA02_mfcc_sma.11. = NA, VA02_mfcc_sma.12. = NA, VA02_mfcc_sma.13. = NA, 
    VA02_mfcc_sma.14. = NA, VA03_F0finEnv_sma = 1.58629187875084e-18, 
    VA03_F0final_sma = -9.46461808448016e-17, VA03_jitterLocal_sma = -2.36937840621222e-17, 
    VA03_shimmerLocal_sma = 2.85381254827705e-17, VA03_mfcc_sma.0. = -9.6294053113996e-17, 
    VA03_mfcc_sma.1. = -5.49550802238737e-17, VA03_mfcc_sma.2. = -2.20247732336464e-17, 
    VA03_mfcc_sma.3. = -4.454892003863e-17, VA03_mfcc_sma.4. = -7.9524696067784e-17, 
    VA03_mfcc_sma.5. = -1.05680749785702e-17, VA03_mfcc_sma.6. = -6.21185832013518e-17, 
    VA03_mfcc_sma.7. = 4.15417752575213e-18, VA03_mfcc_sma.8. = -8.15134676706638e-18, 
    VA03_mfcc_sma.9. = 1.99531361473134e-18, VA03_mfcc_sma.10. = 3.1218480555731e-17, 
    VA03_mfcc_sma.11. = 2.1815428854396e-17, VA03_mfcc_sma.12. = 8.15963331541171e-17, 
    VA03_mfcc_sma.13. = 6.16448325097666e-19, VA03_mfcc_sma.14. = 2.41651014444211e-17, 
    VB01_F0finEnv_sma = NA, VB01_F0final_sma = NA, VB01_jitterLocal_sma = NA, 
    VB01_shimmerLocal_sma = NA, VB01_mfcc_sma.0. = NA, VB01_mfcc_sma.1. = NA, 
    VB01_mfcc_sma.2. = NA, VB01_mfcc_sma.3. = NA, VB01_mfcc_sma.4. = NA, 
    VB01_mfcc_sma.5. = NA, VB01_mfcc_sma.6. = NA, VB01_mfcc_sma.7. = NA, 
    VB01_mfcc_sma.8. = NA, VB01_mfcc_sma.9. = NA, VB01_mfcc_sma.10. = NA, 
    VB01_mfcc_sma.11. = NA, VB01_mfcc_sma.12. = NA, VB01_mfcc_sma.13. = NA, 
    VB01_mfcc_sma.14. = NA), 

VB01.000706 = c(VA01_F0finEnv_sma = NA, 
    VA01_F0final_sma = NA, VA01_jitterLocal_sma = NA, VA01_shimmerLocal_sma = NA, 
    VA01_mfcc_sma.0. = NA, VA01_mfcc_sma.1. = NA, VA01_mfcc_sma.2. = NA, 
    VA01_mfcc_sma.3. = NA, VA01_mfcc_sma.4. = NA, VA01_mfcc_sma.5. = NA, 
    VA01_mfcc_sma.6. = NA, VA01_mfcc_sma.7. = NA, VA01_mfcc_sma.8. = NA, 
    VA01_mfcc_sma.9. = NA, VA01_mfcc_sma.10. = NA, VA01_mfcc_sma.11. = NA, 
    VA01_mfcc_sma.12. = NA, VA01_mfcc_sma.13. = NA, VA01_mfcc_sma.14. = NA, 
    VA02_F0finEnv_sma = NA, VA02_F0final_sma = NA, VA02_jitterLocal_sma = NA, 
    VA02_shimmerLocal_sma = NA, VA02_mfcc_sma.0. = NA, VA02_mfcc_sma.1. = NA, 
    VA02_mfcc_sma.2. = NA, VA02_mfcc_sma.3. = NA, VA02_mfcc_sma.4. = NA, 
    VA02_mfcc_sma.5. = NA, VA02_mfcc_sma.6. = NA, VA02_mfcc_sma.7. = NA, 
    VA02_mfcc_sma.8. = NA, VA02_mfcc_sma.9. = NA, VA02_mfcc_sma.10. = NA, 
    VA02_mfcc_sma.11. = NA, VA02_mfcc_sma.12. = NA, VA02_mfcc_sma.13. = NA, 
    VA02_mfcc_sma.14. = NA, VA03_F0finEnv_sma = NA, VA03_F0final_sma = NA, 
    VA03_jitterLocal_sma = NA, VA03_shimmerLocal_sma = NA, VA03_mfcc_sma.0. = NA, 
    VA03_mfcc_sma.1. = NA, VA03_mfcc_sma.2. = NA, VA03_mfcc_sma.3. = NA, 
    VA03_mfcc_sma.4. = NA, VA03_mfcc_sma.5. = NA, VA03_mfcc_sma.6. = NA, 
    VA03_mfcc_sma.7. = NA, VA03_mfcc_sma.8. = NA, VA03_mfcc_sma.9. = NA, 
    VA03_mfcc_sma.10. = NA, VA03_mfcc_sma.11. = NA, VA03_mfcc_sma.12. = NA, 
    VA03_mfcc_sma.13. = NA, VA03_mfcc_sma.14. = NA, VB01_F0finEnv_sma = 1.85127192814681e-16, 
    VB01_F0final_sma = -5.00994289546507e-17, VB01_jitterLocal_sma = -2.34859079707077e-17, 
    VB01_shimmerLocal_sma = -2.60455164544764e-17, VB01_mfcc_sma.0. = -2.39198962485355e-17, 
    VB01_mfcc_sma.1. = -3.89002856985193e-17, VB01_mfcc_sma.2. = -2.78570899311261e-17, 
    VB01_mfcc_sma.3. = 2.68372615000544e-17, VB01_mfcc_sma.4. = -2.08322992987213e-17, 
    VB01_mfcc_sma.5. = 5.73790146364059e-18, VB01_mfcc_sma.6. = -2.27766888801672e-17, 
    VB01_mfcc_sma.7. = 3.11227273727354e-17, VB01_mfcc_sma.8. = -2.45352291763184e-18, 
    VB01_mfcc_sma.9. = -5.66246851843269e-17, VB01_mfcc_sma.10. = 2.26611187363704e-17, 
    VB01_mfcc_sma.11. = 1.36185358636217e-18, VB01_mfcc_sma.12. = 1.13196270572855e-17, 
    VB01_mfcc_sma.13. = -4.09118309040634e-17, VB01_mfcc_sma.14. = 8.56156119316215e-18
    ))

This is the data's structure str(zF_10_agg_m):

List of 6
 $ VA01.000252: Named num [1:76] 0.1491 0.1209 -0.0786 -0.1141 -0.0642 ...
  ..- attr(*, "names")= chr [1:76] "VA01_F0finEnv_sma" "VA01_F0final_sma" "VA01_jitterLocal_sma" "VA01_shimmerLocal_sma" ...
 $ VA01.000306: Named num [1:76] -0.265 -0.217 0.151 0.21 0.114 ...
  ..- attr(*, "names")= chr [1:76] "VA01_F0finEnv_sma" "VA01_F0final_sma" "VA01_jitterLocal_sma" "VA01_shimmerLocal_sma" ...
 $ VA01.000371: Named num [1:76] 0.1491 0.1209 -0.0786 -0.1141 -0.0642 ...
  ..- attr(*, "names")= chr [1:76] "VA01_F0finEnv_sma" "VA01_F0final_sma" "VA01_jitterLocal_sma" "VA01_shimmerLocal_sma" ...
 $ VA02.000371: Named num [1:76] NA NA NA NA NA NA NA NA NA NA ...
  ..- attr(*, "names")= chr [1:76] "VA01_F0finEnv_sma" "VA01_F0final_sma" "VA01_jitterLocal_sma" "VA01_shimmerLocal_sma" ...
 $ VA03.000389: Named num [1:76] NA NA NA NA NA NA NA NA NA NA ...
  ..- attr(*, "names")= chr [1:76] "VA01_F0finEnv_sma" "VA01_F0final_sma" "VA01_jitterLocal_sma" "VA01_shimmerLocal_sma" ...
 $ VB01.000706: Named num [1:76] NA NA NA NA NA NA NA NA NA NA ...
  ..- attr(*, "names")= chr [1:76] "VA01_F0finEnv_sma" "VA01_F0final_sma" "VA01_jitterLocal_sma" "VA01_shimmerLocal_sma" ...

This is my attempt:

for (i in 1:length(zF_10_agg_m)) {
  for (j in 1:length(zF_10_agg_m[i])) {
    if (grep("F0", names(zF_10_agg_m[[i]])[j]) == F) {
      names(zF_10_agg_m[[i]])[j] <- paste(names(zF_10_agg_m[[i]])[j])
    } else{
      names(zF_10_agg_m[[i]])[j] <-
        paste(names(zF_10_agg_m[[i]])[grep("F0", names(zF_10_agg_m[[i]]))][j], "M", sep = "_")
    }
  }
}

Thank you in advance!

CodePudding user response:

We can use lapply to iterate over your list, then use sub to find names with "F0" (the whole string that contains "F0" is saved in a regex capture group by the surrounding brackets ()) and append "_M" (\\1 is to "call" back the capture group) to it within setNames.

For demonstration purpose, the output is saved to mylist1, where the first list element is pasted here as an example.

mylist1 <- lapply(zF_10_agg_m, \(x) setNames(x, sub("^(.*F0.*)$", "\\1_M", names(x))))

Output

mylist1[[1]]
  VA01_F0finEnv_sma_M    VA01_F0final_sma_M  VA01_jitterLocal_sma 
           0.14909535            0.12092934           -0.07857455 
VA01_shimmerLocal_sma      VA01_mfcc_sma.0.      VA01_mfcc_sma.1. 
          -0.11410235           -0.06422870           -0.03020678 
     VA01_mfcc_sma.2.      VA01_mfcc_sma.3.      VA01_mfcc_sma.4. 
          -0.20854939           -0.19202092           -0.03705184 
     VA01_mfcc_sma.5.      VA01_mfcc_sma.6.      VA01_mfcc_sma.7. 
          -0.09375184            0.07214606           -0.14325611 
     VA01_mfcc_sma.8.      VA01_mfcc_sma.9.     VA01_mfcc_sma.10. 
          -0.07943067           -0.24495994           -0.07746337 
    VA01_mfcc_sma.11.     VA01_mfcc_sma.12.     VA01_mfcc_sma.13. 
           0.00797079           -0.21870903           -0.23046506 
    VA01_mfcc_sma.14.   VA02_F0finEnv_sma_M    VA02_F0final_sma_M 
          -0.16628057                    NA                    NA 
 VA02_jitterLocal_sma VA02_shimmerLocal_sma      VA02_mfcc_sma.0. 
                   NA                    NA                    NA 
     VA02_mfcc_sma.1.      VA02_mfcc_sma.2.      VA02_mfcc_sma.3. 
                   NA                    NA                    NA 
     VA02_mfcc_sma.4.      VA02_mfcc_sma.5.      VA02_mfcc_sma.6. 
                   NA                    NA                    NA 
     VA02_mfcc_sma.7.      VA02_mfcc_sma.8.      VA02_mfcc_sma.9. 
                   NA                    NA                    NA 
    VA02_mfcc_sma.10.     VA02_mfcc_sma.11.     VA02_mfcc_sma.12. 
                   NA                    NA                    NA 
    VA02_mfcc_sma.13.     VA02_mfcc_sma.14.   VA03_F0finEnv_sma_M 
                   NA                    NA                    NA 
   VA03_F0final_sma_M  VA03_jitterLocal_sma VA03_shimmerLocal_sma 
                   NA                    NA                    NA 
     VA03_mfcc_sma.0.      VA03_mfcc_sma.1.      VA03_mfcc_sma.2. 
                   NA                    NA                    NA 
     VA03_mfcc_sma.3.      VA03_mfcc_sma.4.      VA03_mfcc_sma.5. 
                   NA                    NA                    NA 
     VA03_mfcc_sma.6.      VA03_mfcc_sma.7.      VA03_mfcc_sma.8. 
                   NA                    NA                    NA 
     VA03_mfcc_sma.9.     VA03_mfcc_sma.10.     VA03_mfcc_sma.11. 
                   NA                    NA                    NA 
    VA03_mfcc_sma.12.     VA03_mfcc_sma.13.     VA03_mfcc_sma.14. 
                   NA                    NA                    NA 
  VB01_F0finEnv_sma_M    VB01_F0final_sma_M  VB01_jitterLocal_sma 
                   NA                    NA                    NA 
VB01_shimmerLocal_sma      VB01_mfcc_sma.0.      VB01_mfcc_sma.1. 
                   NA                    NA                    NA 
     VB01_mfcc_sma.2.      VB01_mfcc_sma.3.      VB01_mfcc_sma.4. 
                   NA                    NA                    NA 
     VB01_mfcc_sma.5.      VB01_mfcc_sma.6.      VB01_mfcc_sma.7. 
                   NA                    NA                    NA 
     VB01_mfcc_sma.8.      VB01_mfcc_sma.9.     VB01_mfcc_sma.10. 
                   NA                    NA                    NA 
    VB01_mfcc_sma.11.     VB01_mfcc_sma.12.     VB01_mfcc_sma.13. 
                   NA                    NA                    NA 
    VB01_mfcc_sma.14. 
                   NA 
  • Related