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 6027613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:37:06+00:00 2026-05-23T04:37:06+00:00

I am trying the create a loop to extract data from an array created

  • 0

I am trying the create a loop to extract data from an array created previously, so that I can then use the extracted data to generate a line plot.

So far I have been doing it manually by using:

allweek1<-(data.frame(t_weekmean[,,1])) #which selects the date and generates the data frame I want to later format the date using
week1<-stack(allweek1) #and then plot it using
plot(week1$values,type="n", xlim=c(0,2),xlab="Weight (gr)",ylab="Rate (umol/L*gr)",main="All individuals and Treatments at all times")
lines(week1$values[week1$ind=="X9"]~x,type="o",col="red")
lines(week1$values[week1$ind=="X12"]~x,type="o",col="blue")
lines(week1$values[week1$ind=="X15"]~x,type="o",col="green")
lines(week1$values[week1$ind=="X18"]~x,type="o",col="purple").

I know there has to be a way of making this into a loop, for this example I am giving just two weeks but my data goes up to 30, and doing it manually will be messy and easy to have mistakes.

This is the starting array that I have:

, , Week = 1

        Temp
variable       9      12      15      18
    X0   100.000 100.000 100.000 100.000
    X0.5  98.855  98.591  98.357  99.003
    X1    98.004  97.804  97.638  98.299
    X1.5  95.953  96.999  96.810  97.555
    X2    95.235  96.078  95.346  96.665

, , Week = 2

        Temp
variable       9      12      15      18
    X0   100.000 100.000 100.000 100.000
    X0.5  99.137  99.035  97.883  99.055
    X1    98.420  98.298  96.459  97.765
    X1.5  97.939  97.181  94.406  96.546
    X2    96.998  96.237  91.906  95.263

The following data frame which is then converted to a stack version:

          X9     X12     X15     X18
X0   100.000 100.000 100.000 100.000
X0.5  98.855  98.591  98.357  99.003
X1    98.004  97.804  97.638  98.299
X1.5  95.953  96.999  96.810  97.555
X2    95.235  96.078  95.346  96.665

and then the code for plotting is used.

  • 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-05-23T04:37:07+00:00Added an answer on May 23, 2026 at 4:37 am

    Sounds like task for lattice:

    X <- as.data.frame(as.table(t_weekmean), stringsAsFactors=FALSE, responseName="values")
    X$variable <- as.numeric(gsub("^X","",X$variable))
    X$Temp <- as.numeric(X$Temp)
    
    require(lattice)
    xyplot(values~variable|Week, groups=Temp, X, type="o", as.table=TRUE,
        xlab="Weight (gr)", ylab="Rate (umol/L*gr)", main="All individuals and Treatments at all times"
    )
    

    Multi-plot in Lattice

    I recreate your data as:

    t_weekmean <- structure(c(100, 98.855, 98.004, 95.953, 95.235, 100, 98.591, 97.804, 96.999, 96.078, 100, 98.357, 97.638, 96.81, 95.346, 100, 99.003, 98.299, 97.555, 96.665, 100, 99.137, 98.42, 97.939, 96.998, 
    100, 99.035, 98.298, 97.181, 96.237, 100, 97.883, 96.459, 94.406, 91.906, 100, 99.055, 97.765, 96.546, 95.263, 99.9889679441867, 
    98.8470416045204, 98.010997102523, 95.9636806506725, 95.235986063534, 100.00797414162, 98.5968712619705, 97.7984016535804, 96.9904933552904, 
    96.0816877686208, 99.9946318131395, 98.3568674165109, 97.6357767063124, 96.8119443900658, 95.3441814383421, 99.989633272252, 99.0037062049508, 
    98.3034580102509, 97.5568340624981, 96.6615796074679, 100.000379644977, 99.1375077671092, 98.4187321210541, 97.9350205929782, 97.0006243532971, 
    100.003971157774, 99.0316462150477, 98.298322594611, 97.1782003010139, 96.239865449585, 100.002464797458, 97.8810655647218, 96.4592857614756, 
    94.4099917372801, 91.9025173998885, 100.003642400375, 99.0529984607268, 97.76302246443, 96.5426428484451, 95.2658935513329),
    .Dim = c(5L, 4L, 4L), .Dimnames = structure(list(variable = c("X0", "X0.5", "X1", "X1.5", "X2"),
    Temp = c("9", "12", "15", "18"), Week = c("1", "2", "3", "4")), .Names = c("variable", "Temp", "Week"))
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create nested array's dynamically from a string that has been
I'm trying to create a for() loop with JSON data that's already been decoded,
I'm trying to create a multidimensional array from a string (received from $_GET, input
I'm trying to create a loop that will output multiple where statements for a
Im trying to create a simple loop that creates 50 buttons, adds them to
I'm trying to create a simple loop that adds a random number of stars,
I'm trying to create a script that will loop through files that have their
I was trying to create a method that does a loop and in the
I'm trying to create a thread that configures a run loop to run a
I am trying to create a method that return's an array of all CodeIgniter

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.