Hello! I have the following problem. My code: --snip-- ergebnisse <- rep(0, each=2) stichproben <- rep(0, each=2) for (i in seq(1:2)) { n <- dim(daten)[1] ix <- sample(n,200) # producing samples samp_i <- daten[ix,] stichproben[i] <- samp_i # doesn???t works # Calculation of the model: posterior_i <- MCMClogit(y ~ fbl.ind + fekq3 + febitda4 + fuvs + fkru + fzd + fur3, data=samp_i, b0=prior, B0=precision, tune=0.5) # calculation ergebnisse[i] <- summary(posterior_i) # saving the results (works) } --snip-- I have a data set called "daten". I produce samples of the size 200. The samples are saved in samp_i. Question: How is the easiest way to save this samples. My code doesn't work, only the first column of the sample samp_i is in stichproben[i]. I understand why. My idea is to define a array stichproben and then save a matrix in the particular fields of the array. But things like y <- matrix(c(samp_1),nrow=200, ncol=8) and then saving y in the array stichproben doesn't work. How is it possible to define a matrix with the content of my samples (samp_i) and but them into an array stichproben? Or is there an easier way? With kind regards Alex -- Alexander Geisler * Kaltenbach 151 * A-6272 Kaltenbach email: alexander.geisler at gmx.at | alexander.geisler at gmail.com phone: +43 650 / 811 61 90 | skpye: al1405ex
Hi On 7 Dec 2006 at 1:20, Alexander Geisler wrote: Date sent: Thu, 07 Dec 2006 01:20:49 +0100 From: Alexander Geisler <alexander.geisler at gmail.com> To: r-help at stat.math.ethz.ch Subject: [R] Simulation in R> Hello! > > I have the following problem. > > My code: > > --snip-- > > ergebnisse <- rep(0, each=2) > stichproben <- rep(0, each=2) > > for (i in seq(1:2)) { > n <- dim(daten)[1] > ix <- sample(n,200) # producing samples > samp_i <- daten[ix,] > stichproben[i] <- samp_i # doesn??????t worksIf I understand your code correctly, you could use list. stichproben <-vector("list",2) and stichproben[[i]] <- samp_i> > # Calculation of the model: > posterior_i <- MCMClogit(y ~ fbl.ind + fekq3 + febitda4 + fuvs + fkru > + fzd + fur3, data=samp_i, b0=prior, B0=precision, tune=0.5) # > calculation ergebnisse[i] <- summary(posterior_i) # saving the > results (works) } > > --snip-- > > I have a data set called "daten". I produce samples of the size 200. > The samples are saved in samp_i. > > Question: > How is the easiest way to save this samples. My code doesn't work, > only the first column of the sample samp_i is in stichproben[i]. I > understand why. My idea is to define a array stichproben and then save > a matrix in the particular fields of the array. But things like y <- > matrix(c(samp_1),nrow=200, ncol=8) and then saving y in the array > stichproben doesn't work. How is it possible to define a matrix with > the content of my samples (samp_i) and but them into an array > stichproben? Or is there an easier way?Try to look into some documentation to matrix and array. These have limitations that values have to be the same type, but are usually faster to manipulate than data frame. The behavior of objects and assignments depends on nature of objects. The complexity of objects increases in a row vector < matrix < array < data.frame < list and similarly changes possible ways of indexing and susetting HTH Petr> > With kind regards > Alex > > -- > Alexander Geisler * Kaltenbach 151 * A-6272 Kaltenbach > email: alexander.geisler at gmx.at | alexander.geisler at gmail.com > phone: +43 650 / 811 61 90 | skpye: al1405ex > > ______________________________________________ > R-help at stat.math.ethz.ch 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.Petr Pikal petr.pikal at precheza.cz
Dear Alexender ! In the instruction >stichproben[i] <- samp_i , samp_i is a vector while stichproben[i] is vector element It can be better to consider stichproben as a list at beginning e.g >stichproben<-list(0,0) >stichproben[[i]]<-samp_i will work This instruction is >ix <- sample(n,200) is also incorrect because n length is equal to 1 and you want to extract 200 elements >ix <- ifelse(n>=200,sample(1:n, 200),n) Justin BEM Elève Ingénieur Statisticien Economiste BP 294 Yaoundé. Tél (00237)9597295. ----- Message d'origine ---- De : Alexander Geisler <alexander.geisler@gmail.com> À : r-help@stat.math.ethz.ch Envoyé le : Jeudi, 7 Décembre 2006, 1h20mn 49s Objet : [R] Simulation in R Hello! I have the following problem. My code: --snip-- ergebnisse <- rep(0, each=2) stichproben <- rep(0, each=2) for (i in seq(1:2)) { n <- dim(daten)[1] ix <- sample(n,200) # producing samples samp_i <- daten[ix,] stichproben[i] <- samp_i # doesn’t works # Calculation of the model: posterior_i <- MCMClogit(y ~ fbl.ind + fekq3 + febitda4 + fuvs + fkru + fzd + fur3, data=samp_i, b0=prior, B0=precision, tune=0.5) # calculation ergebnisse[i] <- summary(posterior_i) # saving the results (works) } --snip-- I have a data set called "daten". I produce samples of the size 200. The samples are saved in samp_i. Question: How is the easiest way to save this samples. My code doesn't work, only the first column of the sample samp_i is in stichproben[i]. I understand why. My idea is to define a array stichproben and then save a matrix in the particular fields of the array. But things like y <- matrix(c(samp_1),nrow=200, ncol=8) and then saving y in the array stichproben doesn't work. How is it possible to define a matrix with the content of my samples (samp_i) and but them into an array stichproben? Or is there an easier way? With kind regards Alex -- Alexander Geisler * Kaltenbach 151 * A-6272 Kaltenbach email: alexander.geisler@gmx.at | alexander.geisler@gmail.com phone: +43 650 / 811 61 90 | skpye: al1405ex ______________________________________________ R-help@stat.math.ethz.ch 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. ___________________________________________________________________________ Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internaut [[alternative HTML version deleted]]