> 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
7
À : r-help
Objet : [R] Reshape dataframe according to ordered variables
Dear all,
I am still a R apprentice... Apologies for the basic question.
I am trying to reshape a dataframe based on the order of two variables
(a character variable and a numerical variable). To simplify it,
consider the f
try this:
> df
id ord
1 b 2
2 b 1
3 a 1
4 a 3
5 a 2
> df[order(df$id, df$ord),]
id ord
3 a 1
5 a 2
4 a 3
2 b 1
1 b 2
>
On Thu, Mar 18, 2010 at 11:27 AM, Duarte Viana wrote:
> Dear all,
>
> I am still a R apprentice... Apologies for the basic question.
> I am t
Dear all,
I am still a R apprentice... Apologies for the basic question.
I am trying to reshape a dataframe based on the order of two variables
(a character variable and a numerical variable). To simplify it,
consider the following dataframe
> df<-data.frame(id=c("b","b","a","a","a"),ord=c(2,1,1,
Does this do what you want:
> x<-data.frame(id=c(1,2,3), snp1=c("AA","GG",
+ "AG"),snp2=c("GG","AG","GG"),snp3=c("GG","AG","AA"))
> do.call(rbind, apply(x, 1, function(.row){
+ data.frame(c(.row[1], .row[1]),
+strsplit(.row[2], ''),
+strsplit(.row[3], ''),
+
Hi,
I have a large dataset on which I would like to do the following:
x<-data.frame(id=c(1,2,3), snp1=c("AA","GG",
"AG"),snp2=c("GG","AG","GG"),snp3=c("GG","AG","AA"))
> x
id snp1 snp2 snp3
1 1 AA GG GG
2 2 GG AG AG
3 3 AG GG AA
And
On Dec 20, 2007 4:56 PM, Bert Jacobs <[EMAIL PROTECTED]> wrote:
> Hi,
>
> The problem is probably that my Var4, does not contain number but factor
> information, and therefore I think Gabor's suggestion does not work.
> The same holds for Hadley's solution with the functions melt/cast, where the
>
ert Jacobs; 'hadley wickham'
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Reshape Dataframe
I think if you use Gabor's suggested addtion of
add.missing to the original cast command you get what
you want.
cast(dfm, ... ~ Var3, add.missing=TRUE)
--- Bert Jacobs <[EMAIL PROTECTED]> wrot
> Sent: 19 December 2007 17:57
> To: Bert Jacobs; 'hadley wickham'
> Cc: [EMAIL PROTECTED]
> Subject: Re: [R] Reshape Dataframe
>
> I think if you use Gabor's suggested addtion of
> add.missing to the original cast command you get
> what
> you want.
&
In which package do I find the "cast" function. At the moment it's not
recognized.
Thx,
Bert
-Original Message-
From: John Kane [mailto:[EMAIL PROTECTED]
Sent: 19 December 2007 17:57
To: Bert Jacobs; 'hadley wickham'
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Resh
gt;
>
> Thx,
> Bert
>
> -Original Message-
> From: hadley wickham [mailto:[EMAIL PROTECTED]
> Sent: 18 December 2007 15:16
> To: Bert Jacobs
> Cc: [EMAIL PROTECTED]
> Subject: Re: [R] Reshape Dataframe
>
> On 12/18/07, Bert Jacobs <[EMAIL PROTECTED
wickham [mailto:[EMAIL PROTECTED]
Sent: 18 December 2007 15:16
To: Bert Jacobs
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Reshape Dataframe
On 12/18/07, Bert Jacobs <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm having a bit of problems in creating a new dataframe.
> Below you'
On Dec 18, 2007 9:54 AM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
>
> On Dec 18, 2007 9:07 AM, Bert Jacobs <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > I'm having a bit of problems in creating a new dataframe.
> > Below you'll find a description of the current dataframe and of the
> > datafr
On Dec 18, 2007 9:07 AM, Bert Jacobs <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm having a bit of problems in creating a new dataframe.
> Below you'll find a description of the current dataframe and of the
> dataframe that needs to be created.
> Can someone help me out on this one?
> Thx in advance.
On 12/18/07, Bert Jacobs <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm having a bit of problems in creating a new dataframe.
> Below you'll find a description of the current dataframe and of the
> dataframe that needs to be created.
> Can someone help me out on this one?
library(reshape)
dfm <- melt(
Hi,
I'm having a bit of problems in creating a new dataframe.
Below you'll find a description of the current dataframe and of the
dataframe that needs to be created.
Can someone help me out on this one?
Thx in advance.
Bert
Current Dataframe
Var1Var2Var3Var4
A Fa W1
19 matches
Mail list logo