Why not just use gsub
?
Assuming "x" to be your column names (normally accessed via names(your-data-frame)
:
x <- c("agency_id", "site_no", "datetime", "tz_cd", "11_00010",
"11_00010_cd", "12_00030", "12_00030_md")
x <- gsub("11_00010", "temperature", x)
x <- gsub("12_00030", "salinity", x)
x
# [1] "agency_id" "site_no" "datetime" "tz_cd"
# [5] "temperature" "temperature_cd" "salinity" "salinity_md"
Judging by your comments, perhaps you're looking for something more like:
x <- c("agency_id", "site_no", "datetime", "tz_cd", "11_00010",
"11_00010_cd", "12_00030", "12_00030_md")
x[grep("_00010$", x)] <- "temperature"
x[grep("_00030$", x)] <- "salinity"
x
# [1] "agency_id" "site_no" "datetime" "tz_cd"
# [5] "temperature" "11_00010_cd" "salinity" "12_00030_md"