Dear All, Suppose that you have the following data: X Frequency 1 3 4 2 3 4 To get a vector with all observations, one could use data <- c(rep(1,3),rep(4,2),rep(3,4)) I am wondering whether there exists an easier way of doing this. Any ideas? Thanks in advance, Paul
> x <- c(1,4,3) > freq <- c(3,2,4) > rep(x, freq)[1] 1 1 1 4 4 3 3 3 3 Gabor On Mon, Nov 26, 2007 at 07:34:36PM +0000, Paul Smith wrote:> Dear All, > > Suppose that you have the following data: > > X Frequency > 1 3 > 4 2 > 3 4 > > To get a vector with all observations, one could use > > data <- c(rep(1,3),rep(4,2),rep(3,4)) > > I am wondering whether there exists an easier way of doing this. Any ideas? > > Thanks in advance, > > Paul > > ______________________________________________ > 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.-- Csardi Gabor <csardi at rmki.kfki.hu> MTA RMKI, ELTE TTK
On Nov 26, 2007 7:45 PM, Gabor Csardi <csardi at rmki.kfki.hu> wrote:> > x <- c(1,4,3) > > freq <- c(3,2,4) > > rep(x, freq) > [1] 1 1 1 4 4 3 3 3 3Thanks, Gabor. I had just tried rep(1:10,10:20) but should have tried rep(1:10,11:20) Paul> > On Mon, Nov 26, 2007 at 07:34:36PM +0000, Paul Smith wrote: > > Dear All, > > > > Suppose that you have the following data: > > > > X Frequency > > 1 3 > > 4 2 > > 3 4 > > > > To get a vector with all observations, one could use > > > > data <- c(rep(1,3),rep(4,2),rep(3,4)) > > > > I am wondering whether there exists an easier way of doing this. Any ideas? > > > > Thanks in advance, > > > > Paul > > > > ______________________________________________ > > 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. > > -- > Csardi Gabor <csardi at rmki.kfki.hu> MTA RMKI, ELTE TTK >
"Paul Smith" <phhs80 at gmail.com> wrote in news:6ade6f6c0711261153h2cb27f68kbfbc7e6de42e1fa1 at mail.gmail.com:> On Nov 26, 2007 7:45 PM, Gabor Csardi <csardi at rmki.kfki.hu> wrote: >> > x <- c(1,4,3) >> > freq <- c(3,2,4) >> > rep(x, freq) >> [1] 1 1 1 4 4 3 3 3 3 > > Thanks, Gabor. I had just tried > > rep(1:10,10:20) > > but should have tried > > rep(1:10,11:20) >I am wondering it this worked example would be more scaleable? Assuming someone (me) has just copied your table to the clipboard:> dt<-read.table("clipboard",header=TRUE) > dtX Frequency 1 1 3 2 4 2 3 3 4> dt.expand<-rep(dt$X,dt$Frequency) > dt.expand[1] 1 1 1 4 4 3 3 3 3 David Winsemius>> >> On Mon, Nov 26, 2007 at 07:34:36PM +0000, Paul Smith wrote: >> > Dear All, >> > >> > Suppose that you have the following data: >> > >> > X Frequency >> > 1 3 >> > 4 2 >> > 3 4 >> > >> > To get a vector with all observations, one could use >> > >> > data <- c(rep(1,3),rep(4,2),rep(3,4)) >> > >> > I am wondering whether there exists an easier way of doing this. >> > Any ideas? >> >>