Re: [R] Data frame row manipulation

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Fri, 09 May 2008 14:54:14 -0400

Hi Chip,

Try this:

# For Q1
R> C1 = rbind(A,B)

or

R> C2 = do.call(rbind,list(A,B))
R> all.equal(C1,C2) # TRUE

# For Q2

R> set.seed(123)
R> vx=1:10
R> A = matrix(rnorm(500),ncol=10)
R> A2=t(sapply(A,rep,10))
R> A2[vx,]<- A[vx,]
R> A2
R> dim(A2)  # 500  10
R> dim(A)    # 50  10


HTH, Jorge

On Fri, May 9, 2008 at 2:28 PM, Chip Barnaby <cbarnaby_at_wrightsoft.com> wrote:

> Greetings,
>
> Q #1
> ------
>
> How does one combine data frames by row ... no cleverness a la merge(),
> just add rows.
>
> For example, given A with 20 rows and B with 30 rows, I want C = combine(
> A, B) having 50 rows.
>
> Columns having matching names should be filled from both (all) sources with
> suitable coercion, unmatched would get NA in rows whose source does not have
> that column.
>
>
> Q #2
> ------
>
> Given data frame A having various columns including "vx".
>
> I want to create a new data frame A2 that has 10 copies of each row in A,
> all the same as the source row except vx=seq(1:10). The source row value of
> vx is overwritten. A2 would have 10 times as many rows as A.
>
> I have of course discarded idea of using of a for loop, but maybe that is
> what it takes.
>
>
> TIA etc,
>
> Chip Barnaby
>
>
>
>
>
>
> ---------------------------------------------------------
> Chip Barnaby cbarnaby_at_wrightsoft.com
> Vice President of Research
> Wrightsoft Corp. 781-862-8719 x118 voice
> 131 Hartwell Ave 781-861-2058 fax
> Lexington, MA 02421 www.wrightsoft.com
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]



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. Received on Fri 09 May 2008 - 19:29:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 09 May 2008 - 19:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive