Skip to content
Back to formatted view

Raw Message

Message-ID: <20130314112751.Horde.6AQENmEwhY5RQaYnFbgxcXA@webmailnew.dds.nl>
Date: 2013-03-14T10:27:51Z
From: Jan van der Laan
Subject: HOw to achieve big vector times big dataframe in R?
In-Reply-To: <DUB116-W28A7337E8C594E0EEB342186EC0@phx.gbl>

apply((t(as.matrix(b)) * a), 2, sum)

should do what you want.

Why this works; see,  
http://cran.r-project.org/doc/manuals/r-release/R-intro.html#The-recycling-rule and the paragraph before  
that.

Jan



Tammy Ma <metal_licaling at live.com> schreef:

> HI,
>
> I have the following question:
>
> Vector a with lenght 150
>
> A B C D.........
>
> dataframe b with dim 908X150
>
> 1   1   1   1.....
> 2   2   2   2
> 3   3   3   3
> 4   4   4   4
> ................
>
> final result I want is the vector with length 908:
> A*1+B*1+C*1+D*1+.....
> A*2+B*2+C*2+D*2+.....
> A*3+B*3+C*3+D*3+.....
> A*4+B*4+C*4+D*4+.....
> ....
>
> because of too large dimension, how can I achieve this in R? Thanks.
>
> Kind Regards,
> Tammy
>
>
> 	[[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.