Hi I am fairly new to R and I would appreciate some help to hopefully a trivial problem. I created a function: summary.aggregate <- function(y, ...) { temp.mean <- aggregate(y, FUN=mean, ...) temp.sd <- aggregate(y, FUN=sd, ...) temp.length <- aggregate(y, FUN=length, ...) temp <- data.frame(cbind(mean=temp.mean$x,stdev=temp.sd$x,n=temp.length$x)) } this outputs e.g.: mean stdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.98888 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 Is there an easy way to add a column name to the first column? Thank you, Benjamin
names(temp)[1]="a" see: ?names did you really created that function :-)? Mihai Nica 170 East Griffith St. G5 Jackson, MS 39201 601-914-0361 ----- Original Message ---- From: Benjamin Dickgiesser <dickgiesser@gmail.com> To: r-help@stat.math.ethz.ch Sent: Thursday, October 26, 2006 12:08:08 PM Subject: [R] Header of dataframe Hi I am fairly new to R and I would appreciate some help to hopefully a trivial problem. I created a function: summary.aggregate <- function(y, ...) { temp.mean <- aggregate(y, FUN=mean, ...) temp.sd <- aggregate(y, FUN=sd, ...) temp.length <- aggregate(y, FUN=length, ...) temp <- data.frame(cbind(mean=temp.mean$x,stdev=temp.sd$x,n=temp.length$x)) } this outputs e.g.: mean stdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.98888 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 Is there an easy way to add a column name to the first column? Thank you, Benjamin ______________________________________________ R-help@stat.math.ethz.ch 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. [[alternative HTML version deleted]]
Thx for the help but again, this is not what I am looking for. I need the "a" to be over the first column e.g. a mean stdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.98888 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 On 10/26/06, Mihai Nica <mihainica at yahoo.com> wrote:> > names(temp)[1]="a" > > see: ?names > > did you really created that function :-)? > Mihai Nica > 170 East Griffith St. G5 > Jackson, MS 39201 > 601-914-0361 > > > ----- Original Message ---- > From: Benjamin Dickgiesser <dickgiesser at gmail.com> > To: r-help at stat.math.ethz.ch > Sent: Thursday, October 26, 2006 12:08:08 PM > Subject: [R] Header of dataframe > > Hi > I am fairly new to R and I would appreciate some help to hopefully a > trivial problem. > > I created a function: > > summary.aggregate <- function(y, ...) > { > temp.mean <- aggregate(y, FUN=mean, ...) > temp.sd <- aggregate(y, FUN=sd, ...) > temp.length <- aggregate(y, FUN=length, ...) > temp <- > data.frame(cbind(mean=temp.mean$x,stdev=temp.sd$x,n=temp.length$x)) > } > > this outputs e.g.: > > mean stdev n > 1 645.6125 65.94129 60 > 2 655.2121 70.64094 60 > 3 633.3161 80.48620 60 > 4 650.3897 77.59191 60 > 5 630.4955 84.98888 60 > 6 656.2608 66.16100 60 > 7 666.1775 74.39796 60 > 8 663.1543 71.10769 60 > > Is there an easy way to add a column name to the first column? > > Thank you, > Benjamin > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > > >
Oh, I can see now what you mean. That's beyond me, but... why :-)? Mihai Nica 170 East Griffith St. G5 Jackson, MS 39201 601-914-0361 ----- Original Message ---- From: Benjamin Dickgiesser <dickgiesser@gmail.com> To: r-help@stat.math.ethz.ch Sent: Thursday, October 26, 2006 4:35:20 PM Subject: Re: [R] Header of dataframe Thx for the help but again, this is not what I am looking for. I need the "a" to be over the first column e.g. a mean stdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.98888 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 On 10/26/06, Mihai Nica <mihainica@yahoo.com> wrote:> > names(temp)[1]="a" > > see: ?names > > did you really created that function :-)? > Mihai Nica > 170 East Griffith St. G5 > Jackson, MS 39201 > 601-914-0361 > > > ----- Original Message ---- > From: Benjamin Dickgiesser <dickgiesser@gmail.com> > To: r-help@stat.math.ethz.ch > Sent: Thursday, October 26, 2006 12:08:08 PM > Subject: [R] Header of dataframe > > Hi > I am fairly new to R and I would appreciate some help to hopefully a > trivial problem. > > I created a function: > > summary.aggregate <- function(y, ...) > { > temp.mean <- aggregate(y, FUN=mean, ...) > temp.sd <- aggregate(y, FUN=sd, ...) > temp.length <- aggregate(y, FUN=length, ...) > temp <- > data.frame(cbind(mean=temp.mean$x,stdev=temp.sd$x,n=temp.length$x)) > } > > this outputs e.g.: > > mean stdev n > 1 645.6125 65.94129 60 > 2 655.2121 70.64094 60 > 3 633.3161 80.48620 60 > 4 650.3897 77.59191 60 > 5 630.4955 84.98888 60 > 6 656.2608 66.16100 60 > 7 666.1775 74.39796 60 > 8 663.1543 71.10769 60 > > Is there an easy way to add a column name to the first column? > > Thank you, > Benjamin > > ______________________________________________ > R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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. [[alternative HTML version deleted]]
Benjamin Dickgiesser <dickgiesser <at> gmail.com> writes: ...> Is there an easy way to add a column name to the first column?What about summary.aggregate <- function(y, ...) { temp.mean <- aggregate(y, FUN=mean, ...) temp.sd <- aggregate(y, FUN=sd, ...) temp.length <- aggregate(y, FUN=length, ...) temp <- data.frame(cbind(col=names(y), mean=temp.mean$x, stdev=temp.sd$x,n=temp.length$x)) } or summary.aggregate <- function(y, ...) { temp.mean <- aggregate(y, FUN=mean, ...) temp.sd <- aggregate(y, FUN=sd, ...) temp.length <- aggregate(y, FUN=length, ...) temp <- data.frame(cbind(mean=temp.mean$x, stdev=temp.sd$x,n=temp.length$x)) rownames(temp) <- names(y) } Gregor