s-news
[Top] [All Lists]

Re: [S] stacking data.frame

To: Winson Taam <taam@Oakland.edu>
Subject: Re: [S] stacking data.frame
From: Prof Brian D Ripley <ripley@stats.ox.ac.uk>
Date: Wed, 23 Feb 2000 16:04:16 +0000 (GMT)
Cc: s-news@wubios.wustl.edu
In-reply-to: <Pine.OSF.4.21.0002231047550.1930-100000@saturn4.acs.oakland.edu>
Sender: owner-s-news@wubios.wustl.edu
On Wed, 23 Feb 2000, Winson Taam wrote:

> 
> This may sound simple but I can't find a good way to do it.
> 
> tmp is a data.frame with elements
> 
>  a 1
>  c 2
>  b 5
>  b 4
>  a 4
>  c 3
> 
> I want to replicate each row 3 times. i.e.
> 

nr <- nrow(tmp)
tmp[rep(1:nr, rep(3, nr)), , drop=FALSE]

Note that row names in data frames are supposed to be unique, and if
you want to replicate them, make them into another column first.


-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>