[R] Own R function doubt
garciap
garciap at usal.es
Sat Aug 13 16:50:26 CEST 2011
Hi to all the people again,
I was writting a simply function in R, and wish to collect the results in a
excel file. The work goes as follows,
Ciervos<-function(K1, K0, A, R,M,Pi,Hembras)
{B<-(K1-K0)/A
T1<-(R*Pi*Hembras-M*Pi+B)/(Pi-M*Pi+R*Pi*Hembras)
P1<-Pi-B
R1<-P1*Hembras*R
M1<-P1*M
T2<-(R1-M1+B)/(P1-M1+R1)
P2<-P1-B
R2<-P2*Hembras*R
M2<-P2*M
T3<-(R2-M2+B)/(P2-M2+R2)
P3<-P2-B
R3<-P3*Hembras*R
M3<-P3*M
T4<-(R3-M3+B)/(P3-M3+R3)
P4<-P3-B
R4<-P4*Hembras*R
M4<-P4*M
T5<-(R4-M4+B)/(P4-M4+R4)
P5<-P4-B
R5<-P5*Hembras*R
M5<-P5*M
T6<-(R5-M5+B)/(P5-M5+R5)
P6<-P5-B
R6<-P6*Hembras*R
M6<-P6*M
T7<-(R6-M6+B)/(P6-M6+R6)
P7<-P6-B
R7<-P7*Hembras*R
M7<-P7*M
T8<-(R7-M7+B)/(P7-M7+R7)
P8<-P7-B
R8<-P8*Hembras*R
M8<-P8*M
T9<-(R8-M8+B)/(P8-M8+R8)
P9<-P8-B
R9<-P9*Hembras*R
M9<-P9*M
T10<-(R9-M9+B)/(P9-M9+R9)
P10<-P9-B
R10<-P10*Hembras*R
M10<-P10*M
result<-list(B,T1,P1,R1,M1,T2,P2,R2,M2,T3,P4,R4,M4,T5,P5,R5,M5,T6,P6,R6,T6,P7,R7,M7,T8,
P8,R8,M8,T9,P9,R9,M9,T10,P10,R10,M10)
return(result)
}
library(memisc)
Gestion<-as.data.frame(Simulate(Ciervos(K1, K0, A, R,M,Pi,Hembras),
expand.grid(K1=c(420,580),K0=c(300,600),A=3,R=0.4,M=0.1,Pi=420,Hembras=0.5),nsim=1,seed=10000))
xls.getshlib()
write.xls(Gestion, "PoblacionCiervos.xls")
All is fine with the function, by the results (the parameters from B to M10)
are collected in excel by the column names "result 1", "result 2", etc, and
I wish to collect the results with their proper name (B instead of result 1;
T1 instead of result 2, etc).
I will ackonowledge any help, many thanks
pablo
--
View this message in context: http://r.789695.n4.nabble.com/Own-R-function-doubt-tp3741463p3741463.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list