Re: [R] reshape dataframe to array (pivot table)

2012-01-25 Thread Johannes Radinger
> 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 <-

Re: [R] reshape dataframe to array (pivot table)

2012-01-24 Thread Jean V Adams
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) > >

Re: [R] reshape dataframe to array (pivot table)

2012-01-24 Thread Rainer Schuermann
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

[R] reshape dataframe to array (pivot table)

2012-01-24 Thread Johannes Radinger
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

Re: [R] Reshape dataframe according to ordered variables

2010-03-18 Thread MORNEAU François
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

Re: [R] Reshape dataframe according to ordered variables

2010-03-18 Thread jim holtman
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

[R] Reshape dataframe according to ordered variables

2010-03-18 Thread Duarte Viana
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,

Re: [R] reshape dataframe

2009-03-20 Thread jim holtman
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], ''), +

[R] reshape dataframe

2009-03-20 Thread Duijvesteijn, Naomi
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

Re: [R] Reshape Dataframe

2007-12-20 Thread hadley wickham
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 >

Re: [R] Reshape Dataframe

2007-12-20 Thread Bert Jacobs
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

Re: [R] Reshape Dataframe

2007-12-20 Thread John Kane
> 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. &

Re: [R] Reshape Dataframe

2007-12-20 Thread Bert Jacobs
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

Re: [R] Reshape Dataframe

2007-12-19 Thread John Kane
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

Re: [R] Reshape Dataframe

2007-12-18 Thread Bert Jacobs
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'

Re: [R] Reshape Dataframe

2007-12-18 Thread Gabor Grothendieck
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

Re: [R] Reshape Dataframe

2007-12-18 Thread Gabor Grothendieck
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.

Re: [R] Reshape Dataframe

2007-12-18 Thread hadley wickham
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(

[R] Reshape Dataframe

2007-12-18 Thread Bert Jacobs
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