Lizzie Yarwood
Lizzie Yarwood

Reputation: 53

Storing multiple results from for loop

I am using a for loop to perform repeatability analysis on subsets of my data. I am struggling to find a function that will store the results of my for loop in a data frame, because the repeatability analysis output gives R, Standard Error, Confidence Interval, and p-values. I would like to only store R and CI values.

Here is my code:

p<-10000

for(i in 1:P){
  newdf<-df[df$ID %in% sample(unique(df$ID), 16), ]
  m1<-rpt(Behaviour~Temperature+(1|ID),grname="ID",data=newdf,datatype="Gaussian",nboot=1000,npermut=1000)
}

Can anyone help?

Upvotes: 0

Views: 953

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389235

You can create a numeric vector to store R and CI values :

p<-10000
R_value <- numeric(length = p)
CI_value <- numeric(length = p)

for(i in 1:P) {
  newdf<-df[df$ID %in% sample(unique(df$ID), 16), ]
  m1<- rptR::rpt(Behaviour~Temperature+(1|ID),grname="ID",data=newdf,
                 datatype="Gaussian",nboot=1000,npermut=1000)
  R_value[i] <- m1$R
  CI_value[i] <- m1$CI
}

Upvotes: 1

Related Questions