[R] Odp: Loop overwrite and data output problems
RCulloch
ross.culloch at dur.ac.uk
Wed Mar 10 15:37:00 CET 2010
Hi Petr,
Thanks again for your post the problem is now solved - thank you so much for
trying and trying to get this to work.
So the final script that actually worked was:
##ALL SUBSET DATA
#Create vector to put data in
mod <- vector(1000,mode="list")
#first order your data according to ID2
dat.o<-ALL.R[order(ALL.R$ID2),]
#how many values are in each ID2 and a breakpoint fro each ID2
len<-rle(dat.o$ID2)$lengths
shift.len<-c(0,cumsum(len))[-(length(len)+1)]
for(i in 1:1000) {
samp<-sapply(lapply(split(dat.o$ID2, dat.o$ID2), function (x) 1:length
(x)), sample, 1)
Sample.dat<-dat.o[shift.len+samp,]
m1.R<-glm(cbind(Sample.dat$BEH_T, Sample.dat$BEH_F) ~ Sample.dat$SITE +
Sample.dat$YEAR + Sample.dat$PRECIP_MM_DAY + Sample.dat$PUP_AGE_EST +
Sample.dat$MO_AIR_TEMP, family="binomial")
model<-dredge(m1.R)
mod[[i]]<-do.call("rbind", model[1,])}
write.table(mod, "/FILE_PATH/test.txt", col.names=T, row.names=F, sep =
"\t")
Then with the file written to .csv I could open it in excel, transpose the
data and type in the column and row names, a little bit of manual labour c.
3 mins, but worth it!
Really, really appreciate your help with this Petr, I know I wasn't too
clear from the start, but I wasn't entirely sure what the problem was
myself!
Best wishes,
Ross
--
View this message in context: http://n4.nabble.com/Loop-overwrite-and-data-output-problems-tp1570593p1587493.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list