Skip to content
Back to formatted view

Raw Message

Message-ID: <E9DA6CABC0F0734A9980C6E78E9024BA0708D6B8@aai-exch-mbx8.campus.unibe.ch>
Date: 2016-04-07T16:09:07Z
From: maettuw at students.unibe.ch
Subject: Storing output of loop into list()

Hello. I am trying to store the output from a loop into a matrix. Failed so far, thanks for the help.

What I want to store into a new matrix: (just run the code once):

temps<-rnorm(400,14,0.05)
ttind<-NULL
for(ti in 1:(length(temps)-9)) {
  if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
    ttind<-c(ttind,ti)
}
for(ti in 1:length(ttind)) {

 print(round(temps[ttind[ti]:(ttind[ti]+9)],3))

  }







My (failed) soultion attempt:

temps<-rnorm(400,14,0.05)
ttind<-NULL
for(ti in 1:(length(temps)-9)) {
  if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
    ttind<-c(ttind,ti)
}

outputList = list()
counter = 1

for(ti in 1:length(ttind)) {

  outputList[i] <-  print(round(temps[ttind[ti]:(ttind[ti]+9)],3))
counter= counter+1
  }

print(outputList)


	[[alternative HTML version deleted]]