[R] Save a group of matrix

jim holtman jholtman at gmail.com
Thu Feb 21 18:22:13 CET 2008


Look at using a list to store the data, something like this:

> results <- list()
> for (year in 2002:2008){
+     results[[as.character(year)]] <- matrix(year,10,10)
+ }
> results
$`2002`
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002
 [2,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002
 [3,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002
 [4,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002
 [5,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002
 [6,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002
 [7,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002
 [8,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002
 [9,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002
[10,] 2002 2002 2002 2002 2002 2002 2002 2002 2002  2002

$`2003`
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003
 [2,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003
 [3,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003
 [4,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003
 [5,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003
 [6,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003
 [7,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003
 [8,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003
 [9,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003
[10,] 2003 2003 2003 2003 2003 2003 2003 2003 2003  2003

$`2004`


On 2/21/08, Alfonso Pérez Rodríguez <fonsilei at iim.csic.es> wrote:
> It seems that is not posible to send R file in the messages, well, then I
> resend the message with the script included.
>
>
> Hello, I'm creating a loop to work with vegan, to get a species abundance
> curve. Here I send the script I've created and also an excel file to prove
> what it can do.
> Well, I have a database with 20 years, and each year we have sampled 19
> stratum, and in each estratum we have carry out some sumpling. Then, with
> the script that I've sent I've got to calculate the species abundance curve
> for each stratum but only for one year. I want to be able to do this for the
> 20 years sampled but separately, obtaining one independent matrix for each
> year, but I don't know how to do, I sure it's very simple but I've not
> encountered the way to do it.
>
> If someone can help me I would be very grateful, thank you
>
>
> SCRIPT
>
> library(reshape)
> library(vegan)
> Input="D:/R/Analisis aprendizaje/Input"
> setwd(Input)
> Data=read.table("PruebasRNA3.csv",header=T,sep=";",dec=".")
>
> Estr=unique(Data$ESTRATO)
> LEstr=length(Estr)
>
> Results= matrix(nrow=20, ncol=LEstr)
> Results[is.na(Results)]=0
>
> for(i in 1:LEstr)
>  {
>  Datasel=Data[Data$ESTRATO==Estr[i],]
>  SubData=data.frame(Datasel$PESCA, Datasel$Sp, Datasel$Numero)
>  TransData <- reshape(SubData, v.names="Datasel.Numero",
> idvar="Datasel.PESCA",
>                       timevar="Datasel.Sp", direction="wide")
>  TransData[is.na(TransData)] <- 0
>  SAC=specaccum(TransData,"random",permutations=100)
>  # str(SAC), a través de esta función veo cual es la estructura de mis
> datos y puedo pedir las columnas              que me interesen, que en este
> caso serían de la 3 a la 5 (sites, richness y sd)
>  Pesc=length(SAC$richness)
>    for (j in 1:Pesc)
>        {
>        Results[j,i]=SAC$richness[j]
>        }
>  }
> Results
> write.table(Results,file="D:/R/Analisis aprendizaje/Output/Results.txt")
>
>
>
> Alfonso Pérez Rodríguez
> Instituto de Investigaciones Marinas
> C/ Eduardo Cabello nº 6
> C.P. 36208 Vigo (España)
> Tlf.- 986231930 Extensión 241
> e-mail: fonsilei at iim.csic.es
>
>
> --------------------------------------------------------------------------------
>
>
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list