Hello,
I want to rename specific columns in my dataset (columns 15 to 29) by extracting the first 2 or 3 characters in the string. Here is my code:
colnames(d[15:29]) <- sapply(colnames(d[15:29]), function(x){
substr(x, 1,3)
})
.... And nothing happens. What am I doing wrong?
Here is the first row of my data so you can get the column names:
structure(list(STIS. = "1000", Month = "July", Ship = "LE2",
Lake = "Michigan", Site = "EAS5", Station = NA_character_,
Research.Project = "CSMI2021", Date = "7/17/2021", Time..EST. = "15:01 (CDT)",
Site.Depth..m. = 49, Integrated.depths..m. = NA, Separate.depths..m. = 5,
DCL. = "N", Stratified..Unstratified. = "Stratified", NH4.ug.N.L = 19.7,
NOx.ug.N.L = 347, SRP.ug.P.L = 3.51, TN.ug.N.L = 509, TP.ug.P.L = 9.6,
K..mg.L = 1.36, Na..mg.L = 7.26, Ca...mg.L = 31.18, Mg...mg.L = 12.21,
Cl..mg.L = 13, SO4..mg.L = 22.83, Si.mg.SiO2.L = 4.71, chl.a....ug.L = 0.63,
TSS.mg.L = 0.507, VSS.mg.L = 0.513), row.names = 1L, class = "data.frame")
Thanks so much!