Sent: Tuesday, December 07, 2010 11:00 AM
> To: Greg Snow
> Cc: Gene; r-help@r-project.org
> Subject: Re: [R] Efficient way to use data frame of indices to
> initialize matrix
>
>
> On Dec 7, 2010, at 1:49 PM, Greg Snow wrote:
>
> > tmpdf <- data.frame( x = c(
eg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
project.org] On Behalf Of Cutler, Gene
Sent: Tuesday, December 07, 2010 11:31 AM
To: r-help@r-project.org
Subjec
111
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Cutler, Gene
> Sent: Tuesday, December 07, 2010 11:31 AM
> To: r-help@r-project.org
> Subject: [R] Efficient way to use data frame of indices to initialize
> mat
index m as a vector and do the assignment in one step
i <- df$row + (df$col-1)*nrow(m)
m[i] <- df$a
or something along those lines.
-Whit
On Tue, Dec 7, 2010 at 1:31 PM, Cutler, Gene wrote:
> I have a data frame with three columns, x, y, and a. I want to create a
> matrix from these values
I have a data frame with three columns, x, y, and a. I want to create a matrix
from these values such that for matrix m:
m[x,y] == a
Obviously, I can go row by row through the data frame and insert the value a at
the correct x,y location in the matrix. I can make that slightly more
efficient
5 matches
Mail list logo