[R] Odp: Loop overwrite and data output problems
Petr PIKAL
petr.pikal at precheza.cz
Thu Mar 11 08:05:53 CET 2010
Hi
r-help-bounces at r-project.org napsal dne 10.03.2010 15:37:00:
>
> 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,])}
Hm. What is structure of model? From model[1,] I suppose it is matrix or
data frame than why do.call and rbind.
And I suppose mod shall be matrix than why "list" indexing?
start with
mod <- matrix(NA, 1000, ncols)
than use
mod[i,] <- model[1,]
>
>
> write.table(mod, "/FILE_PATH/test.txt", col.names=T, row.names=F, sep =
> "\t")
>
I would transpose it in R by
t(mod)
and if column and row names are repeatably used you can
rownames(mod) <- myrow.names.vector
colnames(mod) <- mycol.names.vector
and after that you can export it with row and col names.
Regards
Petr
> 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.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list