I have a huge DataFrame
, in which I need to extract some information that generates filenames that I need to search in my working directory later, I also need the value in each cell of the pixel column.
For this I created a loop, in which I wanted to search for these pixel names and values based on the name of the columns.
Just like in the example and code below:
Replicable example
###Create a DataFrame
pixel_tot<- data.frame (name= c ("Area A", "Area B", "Area C", "Area D", "Area E", "Area F", "Area G", "Area H ", "Area I",
"Area J", "Area K", "Area L", "Area M", "Area N ", "Area O","Area P"),
AP= c("PI", "PI", "PI", "PI", "UN",
"UN", "UN", "UN", "US", "US", "US","US",
"TI", "TI", "TI", "TI"),
AW= c("wood", "wood", "arc", "arc","wood", "wood", "arc", "arc",
"wood", "wood", "arc", "arc","wood", "wood", "arc", "arc"),
DIST=c("km0", "km10", "km0", "km10","km0", "km10", "km0", "km10","km0", "km10",
"km0", "km10","km0", "km10", "km0", "km10"),
pixels= c(598, 234, 789, 546, 8956, 4454, 7989,
789, 7866, 454, 7846, 968, 5847, 14758, 4578, 5864))
####code
for (k in pixel_tot[,"AW"]) {
for (i in pixel_tot[,"AP"]) {
for (s in pixel_tot[,"pixels"]) {
## I need to get this information about ( AW and AP) to generate a file name that
##I need to call and open, and joining these columns generates that name
print(paste0("control","_",i,"_",k))
### save the pixel value
Pixel_value<- s
print(Pixel_value)
}
}
}
This code does not generate any error, but I expected it to form only 16 combinations, but this is not the case. They generate thousands of different combinations.