1

I have 189 observations that I need to iterate over using a loop. I tried using lapply, but I couldn't figure it out. Here are the first two rows that made the image for me.

image(1:100,1,as.matrix(as.vector(t(Theme[1, 2:101]))), col=c("floralwhite","#EB5B54"), main=Theme[1, 1],xlab="measure",ylab="")

image(1:100,1,as.matrix(as.vector(t(Theme[2, 2:101]))), col=c("floralwhite","#EB5B54"), main=Theme[2, 1],xlab="measure",ylab="")
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Madison
  • 11
  • 1
  • 2
    For a for loop you could do `for(i in 1:189) { print(image(`... your exact code with `Theme[i, 2:101]` instead of `Theme[2, 2:101]` ... `))}`. But you might want to do a little more, e.g., write them to files instead of the viewer pane, maybe add labels. But it's hard to give more guidance without more detail from you. Could you make your example reproducible and give us details on what you might like for labels, file names, etc? – Gregor Thomas Feb 17 '22 at 21:07
  • 3
    What exactly are you looping over? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. We don't need all your data for testing. maybe like three records would be enough to make it clear what you are looping over. What exactly did your `lapply` code look like and in what way did it not do what you want? – MrFlick Feb 17 '22 at 21:07

0 Answers0