Grokbase Groups R r-help April 2010
FAQ
Hello,

I have a data.frame:
name    col1    col2    col3    col4
AA    23    54    0.999    0.78
BB    123    5    1    0.99
AA    203    98    0.79    0.99

I want to get mean value data.frame in terms of name:

name    col1    col2    col3    col4

AA    113.0000  76.0000   0.8945   0.8850

BB    123.00   5.00   1.00   0.99

I tried to use by function:
aa<-by(test[,2:5], feature, mean)
I found aa is "by" function.
class(aa)
[1] "by"

how can I transfer aa to a data frame?

thanks
YU

Search Discussions

  • Tengfei Yin at Apr 29, 2010 at 6:11 am
    Hi

    you could try

    do.call('rbind',aa)

    then turn the matrix into data frame

    regards

    Tengfei
    On Wed, Apr 28, 2010 at 10:56 PM, Yuan Jian wrote:

    Hello,

    I have a data.frame:
    name col1 col2 col3 col4
    AA 23 54 0.999 0.78
    BB 123 5 1 0.99
    AA 203 98 0.79 0.99

    I want to get mean value data.frame in terms of name:

    name col1 col2 col3 col4

    AA 113.0000 76.0000 0.8945 0.8850

    BB 123.00 5.00 1.00 0.99

    I tried to use by function:
    aa<-by(test[,2:5], feature, mean)
    I found aa is "by" function.
    class(aa)
    [1] "by"

    how can I transfer aa to a data frame?

    thanks
    YU






    [[alternative HTML version deleted]]


    ______________________________________________
    r-help@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.

    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name
  • Petr PIKAL at Apr 29, 2010 at 6:30 am
    Hi

    r-help-bounces at r-project.org napsal dne 29.04.2010 08:11:41:
    Hi

    you could try

    do.call('rbind',aa)
    No, No, No. rbind and cbind binds vectors as rows or columns of
    ***matrix***, result is not a data frame

    do.call("rbind",aa)
    X069rutil X102anatas
    105 26.9 7.9
    200 22.8 10.6
    400 30.6 13.3
    600 50.8 20.6
    800 78.7 NA
    exp.df<-do.call("rbind",aa)
    str(exp.df)
    num [1:5, 1:2] 26.9 22.8 30.6 50.8 78.7 7.9 10.6 13.3 20.6 NA
    - attr(*, "dimnames")=List of 2
    ..$ : chr [1:5] "105" "200" "400" "600" ...
    ..$ : chr [1:2] "X069rutil" "X102anatas"

    If some object has rectangular shape and has column names it does not
    automatically mean that it is data frame

    Regards
    Petr


    >
    then turn the matrix into data frame

    regards

    Tengfei
    On Wed, Apr 28, 2010 at 10:56 PM, Yuan Jian wrote:

    Hello,

    I have a data.frame:
    name col1 col2 col3 col4
    AA 23 54 0.999 0.78
    BB 123 5 1 0.99
    AA 203 98 0.79 0.99

    I want to get mean value data.frame in terms of name:

    name col1 col2 col3 col4

    AA 113.0000 76.0000 0.8945 0.8850

    BB 123.00 5.00 1.00 0.99

    I tried to use by function:
    aa<-by(test[,2:5], feature, mean)
    I found aa is "by" function.
    class(aa)
    [1] "by"

    how can I transfer aa to a data frame?

    thanks
    YU






    [[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.

    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name

    [[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.
  • Tengfei Yin at Apr 29, 2010 at 6:44 am
    Hi,

    Thanks, actually I mentioned in the reply, you need to turn the matrix into
    data frame in the end if use this method. e.g

    >
    df=data.frame(name=c('AA','BB','AA'),c1=c(23,123,203),c2=c(54,5,98),c3=c(0.999,1,0.79),c4=c(0.78,0.99,0.99))
    aa=by(df[,2:5],df$name,mean)
    dd=do.call('rbind',aa)
    df=data.frame(dd)
    df
    c1 c2 c3 c4
    AA 113 76 0.8945 0.885
    BB 123 5 1.0000 0.990

    Regards

    Tengfei
    On Thu, Apr 29, 2010 at 1:30 AM, Petr PIKAL wrote:

    Hi

    r-help-bounces@r-project.org napsal dne 29.04.2010 08:11:41:
    Hi

    you could try

    do.call('rbind',aa)
    No, No, No. rbind and cbind binds vectors as rows or columns of
    ***matrix***, result is not a data frame

    do.call("rbind",aa)
    X069rutil X102anatas
    105 26.9 7.9
    200 22.8 10.6
    400 30.6 13.3
    600 50.8 20.6
    800 78.7 NA
    exp.df<-do.call("rbind",aa)
    str(exp.df)
    num [1:5, 1:2] 26.9 22.8 30.6 50.8 78.7 7.9 10.6 13.3 20.6 NA
    - attr(*, "dimnames")=List of 2
    ..$ : chr [1:5] "105" "200" "400" "600" ...
    ..$ : chr [1:2] "X069rutil" "X102anatas"

    If some object has rectangular shape and has column names it does not
    automatically mean that it is data frame

    Regards
    Petr


    then turn the matrix into data frame

    regards

    Tengfei
    On Wed, Apr 28, 2010 at 10:56 PM, Yuan Jian wrote:

    Hello,

    I have a data.frame:
    name col1 col2 col3 col4
    AA 23 54 0.999 0.78
    BB 123 5 1 0.99
    AA 203 98 0.79 0.99

    I want to get mean value data.frame in terms of name:

    name col1 col2 col3 col4

    AA 113.0000 76.0000 0.8945 0.8850

    BB 123.00 5.00 1.00 0.99

    I tried to use by function:
    aa<-by(test[,2:5], feature, mean)
    I found aa is "by" function.
    class(aa)
    [1] "by"

    how can I transfer aa to a data frame?

    thanks
    YU






    [[alternative HTML version deleted]]


    ______________________________________________
    r-help@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.

    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name

    [[alternative HTML version deleted]]

    ______________________________________________
    r-help@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.

    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name
  • Yuan Jian at Apr 29, 2010 at 7:13 am
    Thanks Tengfei,
    I have another question.
    df=data.frame(name=c('AA','BB', 'CC'),c1=c(23,123,5),c2=c(54,5,4),c3=c(0.999,1,23),c4=c(0.78,0.99,54))
    df
    name  c1 c2     c3    c4
    1   AA  23 54  0.999  0.78
    2   BB 123  5  1.000  0.99
    3   CC   5  4 23.000 54.00
    df1=data.frame(name=c('BB','AA', 'DD'),c5=c(98,87,54),c6=c(7,6,3))
    df1
    name c5 c6
    1   BB 98  7
    2   AA 87  6
    3   DD 54  3

    now I want to get interaction for df and df1 in terms of name. this is
    name  c1   c2     c3    c4   c5   c6
    AA     23   54  0.999  0.78  87   6
    BB    123   5   1.000   0.99  98   7

    could give advice?




    --- On Thu, 29/4/10, Tengfei Yin wrote:

    From: Tengfei Yin <yintengfei@gmail.com>
    Subject: Re: [R] by funtion
    To: "Petr PIKAL" <petr.pikal@precheza.cz>
    Cc: "Yuan Jian" <jayuan2008@yahoo.com>, r-help@r-project.org
    Received: Thursday, 29 April, 2010, 6:44 AM

    Hi,
    Thanks, actually I mentioned in the reply, you need to turn the matrix into data frame in the end if use this method. e.g
    df=data.frame(name=c('AA','BB','AA'),c1=c(23,123,203),c2=c(54,5,98),c3=c(0.999,1,0.79),c4=c(0.78,0.99,0.99))
    aa=by(df[,2:5],df$name,mean)> dd=do.call('rbind',aa)> df=data.frame(dd)> df    c1 c2     c3    c4AA 113 76 0.8945 0.885
    BB 123  5 1.0000 0.990
    Regards
    TengfeiOn Thu, Apr 29, 2010 at 1:30 AM, Petr PIKAL wrote:


    Hi



    r-help-bounces@r-project.org napsal dne 29.04.2010 08:11:41:


    Hi >
    you could try >
    do.call('rbind',aa)


    No, No, No. rbind and cbind binds vectors as rows or columns of

    ***matrix***, result is not a data frame



    do.call("rbind",aa)

    X069rutil X102anatas

    105      26.9        7.9

    200      22.8       10.6

    400      30.6       13.3

    600      50.8       20.6

    800      78.7         NA

    exp.df<-do.call("rbind",aa)

    str(exp.df)

    num [1:5, 1:2] 26.9 22.8 30.6 50.8 78.7 7.9 10.6 13.3 20.6 NA

    - attr(*, "dimnames")=List of 2

    ..$ : chr [1:5] "105" "200" "400" "600" ...

    ..$ : chr [1:2] "X069rutil" "X102anatas"



    If some object has rectangular shape and has column names it does not

    automatically mean that it is data frame



    Regards

    Petr





    >



    >
    then turn the matrix into data frame >
    regards >
    Tengfei >
    On Wed, Apr 28, 2010 at 10:56 PM, Yuan Jian wrote:
    >
    Hello,
    > >
    I have a data.frame:
    name    col1    col2    col3    col4
    AA    23    54    0.999    0.78
    BB    123    5    1    0.99
    AA    203    98    0.79    0.99
    > >
    I want to get mean value data.frame in terms of name:
    > >
    name    col1    col2    col3    col4
    > >
    AA    113.0000  76.0000   0.8945   0.8850
    > >
    BB    123.00   5.00   1.00   0.99
    > >
    I tried to use by function:
    > >
    aa<-by(test[,2:5], feature, mean)
    I found aa is "by" function.
    class(aa)
    [1] "by"
    > >
    how can I transfer aa to a data frame?
    > >
    thanks
    YU
    > >

    > >

    > >

    > >

    > >

    > >
    [[alternative HTML version deleted]]
    > >

    > >
    ______________________________________________
    r-help@r-project.org mailing list
    PLEASE do read the posting guide
    and provide commented, minimal, self-contained, reproducible code.
    > >

    > >

    >

    >
    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name >
    [[alternative HTML version deleted]] >
    ______________________________________________
    r-help@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.





    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name
  • Petr PIKAL at Apr 29, 2010 at 7:20 am
    Hi

    probably merge is what you want

    see

    ?merge
    Regards
    Petr

    r-help-bounces at r-project.org napsal dne 29.04.2010 09:13:34:
    Thanks Tengfei,
    I have another question.
    df=data.frame(name=c('AA','BB',
    'CC'),c1=c(23,123,5),c2=c(54,5,4),c3=c(0.
    999,1,23),c4=c(0.78,0.99,54))
    df
    name c1 c2 c3 c4
    1 AA 23 54 0.999 0.78
    2 BB 123 5 1.000 0.99
    3 CC 5 4 23.000 54.00
    df1=data.frame(name=c('BB','AA', 'DD'),c5=c(98,87,54),c6=c(7,6,3))
    df1
    name c5 c6
    1 BB 98 7
    2 AA 87 6
    3 DD 54 3

    now I want to get interaction for df and df1 in terms of name. this is
    name c1 c2 c3 c4 c5 c6
    AA 23 54 0.999 0.78 87 6
    BB 123 5 1.000 0.99 98 7

    could give advice?




    --- On Thu, 29/4/10, Tengfei Yin wrote:

    From: Tengfei Yin <yintengfei@gmail.com>
    Subject: Re: [R] by funtion
    To: "Petr PIKAL" <petr.pikal@precheza.cz>
    Cc: "Yuan Jian" <jayuan2008@yahoo.com>, r-help at r-project.org
    Received: Thursday, 29 April, 2010, 6:44 AM

    Hi,
    Thanks, actually I mentioned in the reply, you need to turn the matrix into
    data frame in the end if use this method. e.g
    df=data.frame(name=c('AA','BB','AA'),c1=c(23,123,203),c2=c(54,5,98),c3=c(0.
    999,1,0.79),c4=c(0.78,0.99,0.99))
    aa=by(df[,2:5],df$name,mean)> dd=do.call('rbind',aa)>
    df=data.frame(dd)>
    df c1 c2 c3 c4AA 113 76 0.8945 0.885

    BB 123 5 1.0000 0.990
    Regards
    TengfeiOn Thu, Apr 29, 2010 at 1:30 AM, Petr PIKAL wrote:

    Hi



    r-help-bounces at r-project.org napsal dne 29.04.2010 08:11:41:


    Hi

    you could try

    do.call('rbind',aa)


    No, No, No. rbind and cbind binds vectors as rows or columns of

    ***matrix***, result is not a data frame



    do.call("rbind",aa)

    X069rutil X102anatas

    105 26.9 7.9

    200 22.8 10.6

    400 30.6 13.3

    600 50.8 20.6

    800 78.7 NA

    exp.df<-do.call("rbind",aa)

    str(exp.df)

    num [1:5, 1:2] 26.9 22.8 30.6 50.8 78.7 7.9 10.6 13.3 20.6 NA

    - attr(*, "dimnames")=List of 2

    ..$ : chr [1:5] "105" "200" "400" "600" ...

    ..$ : chr [1:2] "X069rutil" "X102anatas"



    If some object has rectangular shape and has column names it does not

    automatically mean that it is data frame



    Regards

    Petr






    then turn the matrix into data frame

    regards

    Tengfei

    On Wed, Apr 28, 2010 at 10:56 PM, Yuan Jian <jayuan2008@yahoo.com> wrote:

    Hello,
    I have a data.frame:
    name col1 col2 col3 col4
    AA 23 54 0.999 0.78
    BB 123 5 1 0.99
    AA 203 98 0.79 0.99
    I want to get mean value data.frame in terms of name:
    name col1 col2 col3 col4
    AA 113.0000 76.0000 0.8945 0.8850
    BB 123.00 5.00 1.00 0.99
    I tried to use by function:

    aa<-by(test[,2:5], feature, mean)
    I found aa is "by" function.
    class(aa)
    [1] "by"
    how can I transfer aa to a data frame?
    thanks
    YU
    [[alternative HTML version deleted]]
    ______________________________________________
    R-help at r-project.org mailing list
    PLEASE do read the posting guide
    and provide commented, minimal, self-contained, reproducible code.


    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name

    [[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.





    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name









    [[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.
  • Tengfei Yin at Apr 29, 2010 at 7:59 am
    Hi Petr,

    Thanks for your suggestions:)

    @Yuan,

    Petr is right, you can try

    merge(df,df1,'name')

    Regards

    Tengfei

    On Thu, Apr 29, 2010 at 2:20 AM, Petr PIKAL wrote:

    Hi

    probably merge is what you want

    see

    ?merge
    Regards
    Petr

    r-help-bounces@r-project.org napsal dne 29.04.2010 09:13:34:
    Thanks Tengfei,
    I have another question.
    df=data.frame(name=c('AA','BB',
    'CC'),c1=c(23,123,5),c2=c(54,5,4),c3=c(0.
    999,1,23),c4=c(0.78,0.99,54))
    df
    name c1 c2 c3 c4
    1 AA 23 54 0.999 0.78
    2 BB 123 5 1.000 0.99
    3 CC 5 4 23.000 54.00
    df1=data.frame(name=c('BB','AA', 'DD'),c5=c(98,87,54),c6=c(7,6,3))
    df1
    name c5 c6
    1 BB 98 7
    2 AA 87 6
    3 DD 54 3

    now I want to get interaction for df and df1 in terms of name. this is
    name c1 c2 c3 c4 c5 c6
    AA 23 54 0.999 0.78 87 6
    BB 123 5 1.000 0.99 98 7

    could give advice?




    --- On Thu, 29/4/10, Tengfei Yin wrote:

    From: Tengfei Yin <yintengfei@gmail.com>
    Subject: Re: [R] by funtion
    To: "Petr PIKAL" <petr.pikal@precheza.cz>
    Cc: "Yuan Jian" <jayuan2008@yahoo.com>, r-help@r-project.org
    Received: Thursday, 29 April, 2010, 6:44 AM

    Hi,
    Thanks, actually I mentioned in the reply, you need to turn the matrix into
    data frame in the end if use this method. e.g
    df=data.frame(name=c('AA','BB','AA'),c1=c(23,123,203),c2=c(54,5,98),c3=c(0.
    999,1,0.79),c4=c(0.78,0.99,0.99))
    aa=by(df[,2:5],df$name,mean)> dd=do.call('rbind',aa)>
    df=data.frame(dd)>
    df c1 c2 c3 c4AA 113 76 0.8945 0.885

    BB 123 5 1.0000 0.990
    Regards
    TengfeiOn Thu, Apr 29, 2010 at 1:30 AM, Petr PIKAL wrote:

    Hi



    r-help-bounces@r-project.org napsal dne 29.04.2010 08:11:41:


    Hi

    you could try

    do.call('rbind',aa)


    No, No, No. rbind and cbind binds vectors as rows or columns of

    ***matrix***, result is not a data frame



    do.call("rbind",aa)

    X069rutil X102anatas

    105 26.9 7.9

    200 22.8 10.6

    400 30.6 13.3

    600 50.8 20.6

    800 78.7 NA

    exp.df<-do.call("rbind",aa)

    str(exp.df)

    num [1:5, 1:2] 26.9 22.8 30.6 50.8 78.7 7.9 10.6 13.3 20.6 NA

    - attr(*, "dimnames")=List of 2

    ..$ : chr [1:5] "105" "200" "400" "600" ...

    ..$ : chr [1:2] "X069rutil" "X102anatas"



    If some object has rectangular shape and has column names it does not

    automatically mean that it is data frame



    Regards

    Petr






    then turn the matrix into data frame

    regards

    Tengfei

    On Wed, Apr 28, 2010 at 10:56 PM, Yuan Jian <jayuan2008@yahoo.com> wrote:

    Hello,
    I have a data.frame:
    name col1 col2 col3 col4
    AA 23 54 0.999 0.78
    BB 123 5 1 0.99
    AA 203 98 0.79 0.99
    I want to get mean value data.frame in terms of name:
    name col1 col2 col3 col4
    AA 113.0000 76.0000 0.8945 0.8850
    BB 123.00 5.00 1.00 0.99
    I tried to use by function:

    aa<-by(test[,2:5], feature, mean)
    I found aa is "by" function.
    class(aa)
    [1] "by"
    how can I transfer aa to a data frame?
    thanks
    YU
    [[alternative HTML version deleted]]
    ______________________________________________
    r-help@r-project.org mailing list
    PLEASE do read the posting guide
    and provide commented, minimal, self-contained, reproducible code.


    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name

    [[alternative HTML version deleted]]

    ______________________________________________
    r-help@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.





    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name









    [[alternative HTML version deleted]]

    ______________________________________________
    r-help@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.
    ______________________________________________
    r-help@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.


    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name
  • Petr PIKAL at Apr 29, 2010 at 7:18 am
    Hi

    sorry I did not read your reply as thoroughly. But generally matrices are
    quite often exchanged for data frames. Also if you have list with mixture
    of numeric and nonumeric data such approach results in nonumeric output as
    matrix can have values only of one type. I would therefore generally
    prefer
    dd=do.call('data.frame',aa)
    dd
    AA BB
    c1 113.0000 123.00
    c2 76.0000 5.00
    c3 0.8945 1.00
    c4 0.8850 0.99
    t(dd)
    c1 c2 c3 c4
    AA 113 76 0.8945 0.885
    BB 123 5 1.0000 0.990

    approach

    Regards
    Petr

    r-help-bounces at r-project.org napsal dne 29.04.2010 08:44:10:
    Hi,

    Thanks, actually I mentioned in the reply, you need to turn the matrix into
    data frame in the end if use this method. e.g
    df=data.frame(name=c('AA','BB','AA'),c1=c(23,123,203),c2=c(54,5,98),c3=c(0.
    999,1,0.79),c4=c(0.78,0.99,0.99))
    aa=by(df[,2:5],df$name,mean)
    dd=do.call('rbind',aa)
    df=data.frame(dd)
    df
    c1 c2 c3 c4
    AA 113 76 0.8945 0.885
    BB 123 5 1.0000 0.990

    Regards

    Tengfei
    On Thu, Apr 29, 2010 at 1:30 AM, Petr PIKAL wrote:

    Hi

    r-help-bounces at r-project.org napsal dne 29.04.2010 08:11:41:
    Hi

    you could try

    do.call('rbind',aa)
    No, No, No. rbind and cbind binds vectors as rows or columns of
    ***matrix***, result is not a data frame

    do.call("rbind",aa)
    X069rutil X102anatas
    105 26.9 7.9
    200 22.8 10.6
    400 30.6 13.3
    600 50.8 20.6
    800 78.7 NA
    exp.df<-do.call("rbind",aa)
    str(exp.df)
    num [1:5, 1:2] 26.9 22.8 30.6 50.8 78.7 7.9 10.6 13.3 20.6 NA
    - attr(*, "dimnames")=List of 2
    ..$ : chr [1:5] "105" "200" "400" "600" ...
    ..$ : chr [1:2] "X069rutil" "X102anatas"

    If some object has rectangular shape and has column names it does not
    automatically mean that it is data frame

    Regards
    Petr


    then turn the matrix into data frame

    regards

    Tengfei

    On Wed, Apr 28, 2010 at 10:56 PM, Yuan Jian <jayuan2008@yahoo.com>
    wrote:
    Hello,

    I have a data.frame:
    name col1 col2 col3 col4
    AA 23 54 0.999 0.78
    BB 123 5 1 0.99
    AA 203 98 0.79 0.99

    I want to get mean value data.frame in terms of name:

    name col1 col2 col3 col4

    AA 113.0000 76.0000 0.8945 0.8850

    BB 123.00 5.00 1.00 0.99

    I tried to use by function:
    aa<-by(test[,2:5], feature, mean)
    I found aa is "by" function.
    class(aa)
    [1] "by"

    how can I transfer aa to a data frame?

    thanks
    YU






    [[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.

    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name

    [[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.

    --
    Tengfei Yin
    MCDB PhD student
    1620 Howe Hall, 2274,
    Iowa State University
    Ames, IA,50011-2274
    Homepage: www.tengfei.name

    [[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.
  • Petr PIKAL at Apr 29, 2010 at 6:12 am
    Hi


    r-help-bounces at r-project.org napsal dne 29.04.2010 05:56:23:
    Hello,

    I have a data.frame:
    name col1 col2 col3 col4
    AA 23 54 0.999 0.78
    BB 123 5 1 0.99
    AA 203 98 0.79 0.99

    I want to get mean value data.frame in terms of name:

    name col1 col2 col3 col4

    AA 113.0000 76.0000 0.8945 0.8850

    BB 123.00 5.00 1.00 0.99

    I tried to use by function:
    aa<-by(test[,2:5], feature, mean)
    I found aa is "by" function.
    class(aa)
    [1] "by"

    how can I transfer aa to a data frame?
    use aggregate instead

    aa<-aggregate(test[,2:5], feature, mean)

    Regards
    Petr
    thanks
    YU






    [[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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedApr 29, '10 at 3:56a
activeApr 29, '10 at 7:59a
posts9
users3
websiter-project.org
irc#r

People

Translate

site design / logo © 2022 Grokbase