Hi Nanthinee, Use ?rep it will rep()licate each x, freq times.
dat <- data.frame(freq = c(30, 70, 100, 22, 250), x = c(7, 8, 7, 6, 10)) total <- rep(dat$x, dat$freq) > length(total) [1] 472 Cheers, Josh On Thu, Jul 7, 2011 at 9:24 PM, nanthinee <nanthin...@gmail.com> wrote: > Hi, > > I have a dataset: > > freq x > 1 30 7 > 3 70 8 > 4 100 7 > 5 22 6 > 6 250 10 > > How do I convert into vector form (v<- 7,7,7,8,8,8,6,6,6,6) all "x" with the > complete frequency? Transpose only does a single row but I want the full > frequencies not just the variable transposed. > > Thanks, > Nanthinee > > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-convert-matrix-with-frequency-variable-to-vector-tp3653196p3653196.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/ ______________________________________________ R-help@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.