Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:25:51+00:00 2026-06-01T19:25:51+00:00

I am trying to code a for loop from a matrix to create a

  • 0

I am trying to code a for loop from a matrix to create a series of plots on a pdf. Here is my code:

pdf("/Users/Aurelz/Documents/Shark Research/DFO-data/Arctic/plots.pdf", height=8, width=6.5)
par(mfrow=c(3,2), mar=c(0.8,0.8,0.8,0.8), oma=c(2,2,1,1.5), mgp=c(0.5,0.5,0))

for (i in c("JUL","AUG","SEPT","OCT","NOV","DEC")){
  plot(Thorny.Lmm[["r","i"]], Thorny.Lmm[["Lmm","i"]], type="l")
  abline(h=0, lty=2) 
  title(main="Thorny skate in i")
}
dev.off()

>Error in Thorny.Lmm[["r", "i"]] : subscript out of bounds

Thorny.Lmm is a matrix of the following format:

> Thorny.Lmm
    JUL         AUG         SEPT        OCT         NOV         DEC        
r   Numeric,513 Numeric,513 Numeric,513 Numeric,513 Numeric,513 Numeric,513
Kmm Numeric,513 Numeric,513 Numeric,513 Numeric,513 Numeric,513 Numeric,513
Lmm Numeric,513 Numeric,513 Numeric,513 Numeric,513 Numeric,513 Numeric,513

I first tried this code, which worked fine.

plot(Thorny.Lmm[["r","JUL"]], Thorny.Lmm[["Lmm","JUL"]], type="l")
abline(h=0, lty=2)
title(main="Thorny JUL")

I’m sure it’s fairly straightforward to fix, but I just can’t get my head around it (until now anyway)!

Thank you for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:25:52+00:00Added an answer on June 1, 2026 at 7:25 pm

    You want the value of the variable i rather than the quoted string "i":

    for (i in c("JUL","AUG","SEPT","OCT","NOV","DEC")){
      plot(Thorny.Lmm[["r",i]], Thorny.Lmm[["Lmm",i]], type="l")
      abline(h=0, lty=2) 
      title(main=paste("Thorny skate in", i))
    }
    dev.off()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to create a matrix-like program with raining green code. Everything has
So I'm trying to create a set of directories from a while loop. The
I am trying the create a loop to extract data from an array created
I'm trying to understand some assembler code inside a loop. The loop runs from
I am trying to make a loop which will create a matrix of appropriate
In the below code I'm trying to loop through each child node and append
I'm trying to understand why my code get stuck in the for loop of
I'm trying to populate a dictionary dynamically in a for loop like so: pseudo-code
I am having problems with my JScript code. I am trying to loop through
I'm trying to export ALL records from a Visual Collection to excel. My code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.