I want to loop over a list of chr values in R. For ervery value I want to run the next code
for (locatie in Locaties){ # Locaties is a list of character values ("NL14_20076" "NL14_20077" etc)
Data_ammoniak <- subset(paste0("Data_",locatie), Parameter == "ammoniak")
# I want to make a dataset with only ammoniak data out of a dataset called "Data_NL14_20076"
# So I want to use the value from the list
ggplot(Data_ammoniak, aes(x = Begindatum, y = Meetwaarde_n)) +
geom_point() +
geom_line() +
labs(x = "Datum",
y = "Meetwaarde",
title = paste0(locatie, "Ammoniak")) # This one is working I think
ggsave(paste0("C:/Temp/LTO_Noord/",locatie,"_Ammoniak.png"), #This one is working as well I think
width = 30,
height = 20,
units = "cm")
}
When I run this code I get the following error:
Error in subset.default(paste0("Data_", locatie), Parameter == "ammoniak") :
object 'Parameter' not found
Does somebody know how it will work?