> An: Johannes Radinger
> CC: "r-help@r-project.org"
> Betreff: Re: [R] reshape dataframe to array (pivot table)
> Hi,
>
> I wouldn't know how to fill the data into the array form you want, but
> you can get the aggregated data with
>
> dfm <-
Johannes Radinger wrote on 01/24/2012 10:15:29 AM:
> Hello,
>
> I would like to reshape a dataframe into an array. This is kind a
> similar task as Excel performs with a Pivot table. To illustrate it:
>
> LOC <- factor(c(1,2,2,3,1,1))
> SPEC1 <- c(0,0,23,0,12,11)
> SPEC2 <- c(1,2,0,0,0,4)
>
>
Hi,
I wouldn't know how to fill the data into the array form you want, but
you can get the aggregated data with
dfm <- melt( df )
dfc <- cast( dfm, LOC ~ variable, sum )
> dfc
LOC SPEC1 SPEC2
1 123 5
2 223 2
3 3 0 0
Hope this helps as a first step!
Rgds,
Raine
Hello,
I would like to reshape a dataframe into an array. This is kind a similar task
as Excel performs with a Pivot table. To illustrate it:
LOC <- factor(c(1,2,2,3,1,1))
SPEC1 <- c(0,0,23,0,12,11)
SPEC2 <- c(1,2,0,0,0,4)
df <- data.frame(LOC,SPEC1,SPEC2) # original dataframe
a <-
array(NA,d
4 matches
Mail list logo