Dear R users, I am a new user (probably obvious by my question) and have really learned a lot from reading this list. Thank you all very much. My main struggles with R are with data manipulation. So here is my question... I have data that is organized as below, this is a short example. value count 11232 25 15885 24 22464 20 etc... the 'value' field is distances and the 'count' field is the number of times that each distance occurs. So I guess it is in the same format as the output for the table() function. What I need to do is make one long vector (or list) that includes all the actual numbers. In other words 11232 listed 25 times followed by 15885 listed 24 times etc. etc. Thank you again in advance, Michael ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page.
Henrique Dallazuanna
2008-Jan-27 20:58 UTC
[R] Data manipulation question (opposite of table?)
Try this: rep(x[[1]], x[[2]]) On 27/01/2008, Michael Denslow <mwdenslow at yahoo.com> wrote:> Dear R users, > > I am a new user (probably obvious by my question) and > have really learned a lot from reading this list. > Thank you all very much. My main struggles with R are > with data manipulation. > > So here is my question... > I have data that is organized as below, this is a > short example. > > value count > 11232 25 > 15885 24 > 22464 20 > etc... > > the 'value' field is distances and the 'count' field > is the number of times that each distance occurs. So I > guess it is in the same format as the output for the > table() function. > > What I need to do is make one long vector (or list) > that includes all the actual numbers. In other words > 11232 listed 25 times followed by 15885 listed 24 > times etc. etc. > > Thank you again in advance, > Michael > > > > > > > > > > ____________________________________________________________________________________ > Never miss a thing. Make Yahoo your home page. > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Michael Denslow <mwdenslow at yahoo.com> wrote in news:316086.62237.qm at web33112.mail.mud.yahoo.com:> Dear R users, > > I am a new user (probably obvious by my question) and > have really learned a lot from reading this list. > Thank you all very much. My main struggles with R are > with data manipulation. > > So here is my question... > I have data that is organized as below, this is a > short example. > > value count > 11232 25 > 15885 24 > 22464 20 > etc... > > the 'value' field is distances and the 'count' field > is the number of times that each distance occurs. So I > guess it is in the same format as the output for the > table() function. > > What I need to do is make one long vector (or list) > that includes all the actual numbers. In other words > 11232 listed 25 times followed by 15885 listed 24 > times etc. etc.Try something like this? dt<-data.frame(value=c(11123,14585),count=c(3,5)) exp.dt<-with(dt,rep(value,count))> exp.dt[1] 11123 11123 11123 14585 14585 14585 14585 14585 -- David Winsemius