I have a list of colors called mergedColors
. From this list of colors, I use a for()
loop to go though and create a matrix corresponding to each unique color. Up until this point, everything works fine. I then want to go and continue to alter/edit the matrices in the loop after I have initially created them. In the example, I try to change the name of the third column. However, I'm not entirely sure how to go about doing that. When I try to call them through the same syntax that I used to create them,
colnames(paste("merged",each,sep="_"))[3] = "Temp"
R returns an error: "target of assignment expands to non-language object". How should I call the matrices I just created while still inside the loop?
Sample data:
mergedColors = c("red", "blue", "green", "red", "black", "blue", "blue", "green", "yellow", "red")
table(mergedColors)
for(each in unique(mergedColors)){
assign(paste("merged",each,sep="_"), as.matrix(cbind(cars, c(each))))
#colnames(paste("merged",each,sep="_"))[3] = "Temp"
}