[R] Save a group of matrix
Alfonso Pérez Rodríguez
fonsilei at iim.csic.es
Thu Feb 21 16:58:41 CET 2008
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 en iim.csic.es
--------------------------------------------------------------------------------
> ______________________________________________
> R-help en 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.
>
More information about the R-help
mailing list