Dear All, I have a data frame like this: name ip Bsent Breceived a 1 0.00 0.00 a 2 1.43 19.83 a 1 0.00 0.00 a 2 1.00 1.00 b 1 0.00 2.00 b 3 0.00 2.00 b 2 2.00 0.00 b 2 2.00 0.00 b 1 24.40 22.72 c 1 1.00 1.00 c 1 2.00 1.00 c 1 2.00 1.00 c 1 90.97 15.70 d 0 0.00 0.00 d 1 30.00 17.14 I want to sum up the similar name into one row, like : name ip Bsent Breceived a 6 2.43 20.83 b 9 28.40 26.72 c d I need help to sum up. Thanks for your time. Thanks & Rg Mohan L
On Nov 7, 2010, at 8:59 AM, Mohan L wrote:> Dear All, > > I have a data frame like this: > > name ip Bsent Breceived > a 1 0.00 0.00 > a 2 1.43 19.83 > a 1 0.00 0.00 > a 2 1.00 1.00 > b 1 0.00 2.00 > b 3 0.00 2.00 > b 2 2.00 0.00 > b 2 2.00 0.00 > b 1 24.40 22.72 > c 1 1.00 1.00 > c 1 2.00 1.00 > c 1 2.00 1.00 > c 1 90.97 15.70 > d 0 0.00 0.00 > d 1 30.00 17.14 > > I want to sum up the similar name into one row, like : > > name ip Bsent Breceived > a 6 2.43 20.83 > b 9 28.40 26.72 > c > d?aggregate > dfrm <- rd.txt("name ip Bsent Breceived + a 1 0.00 0.00 + a 2 1.43 19.83 + a 1 0.00 0.00 + a 2 1.00 1.00 + b 1 0.00 2.00 + b 3 0.00 2.00 + b 2 2.00 0.00 + b 2 2.00 0.00 + b 1 24.40 22.72 + c 1 1.00 1.00 + c 1 2.00 1.00 + c 1 2.00 1.00 + c 1 90.97 15.70 + d 0 0.00 0.00 + d 1 30.00 17.14") > aggregate(dfrm[ , -1], list(dfrm[,1]), sum) Group.1 ip Bsent Breceived 1 a 6 2.43 20.83 2 b 9 28.40 26.72 3 c 4 95.97 18.70 4 d 1 30.00 17.14 -- David> > I need help to sum up. Thanks for your time. > > > Thanks & Rg > Mohan L > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
With your data set as the data.frame xx library(reshape2) xx <- melt(xx) dcast(xx, name ~ variable, sum) --- On Sun, 11/7/10, Mohan L <l.mohanphysics at gmail.com> wrote:> From: Mohan L <l.mohanphysics at gmail.com> > Subject: [R] help to sum up data frame > To: r-help at r-project.org > Received: Sunday, November 7, 2010, 8:59 AM > Dear All, > > I have a data frame like this: > > name? ? ? ip? ? ? Bsent? > ???Breceived > a? ? ? ? ???1? > ? ? ? 0.00? ? ? 0.00 > a? ? ? ? ???2? > ? ???1.43? ? > ???19.83 > a? ? ? ? ???1? > ? ???0.00? ? ? 0.00 > a? ? ? ? ? 2? ? ? > ? 1.00? ? ? 1.00 > b? ? ? ? ? 1? ? ? > ? 0.00? ? ? 2.00 > b? ? ? ? ? 3? ? > ???0.00? ? ? 2.00 > b? ? ? ? ? 2? ? > ???2.00? ? ? 0.00 > b? ? ? ???2? ? > ???2.00? ? ? 0.00 > b? ? ? ???1? ? > ???24.40? ???22.72 > c? ? ? ???1? ? > ???1.00? ? ? 1.00 > c? ? ? ???1? ? > ???2.00? ? ? 1.00 > c? ? ? ???1? ? > ???2.00? ? ? 1.00 > c? ? ? ???1? ? > ? 90.97? ? ? 15.70 > d? ? ? ???0? ? > ???0.00? ? ? 0.00 > d? ? ? ???1? > ???30.00? ??? ? > ? 17.14 > > I want to sum up the similar name into one row, like : > > name? ? ? ip? ? ? Bsent? > ???Breceived > a? ? ? ? ? ? 6? ? > ? ? 2.43? ? ? 20.83 > b? ? ? ? ? ? 9? ? > ???28.40? ???26.72 > c > d > > I need help to sum up. Thanks for your time. > > > Thanks & Rg > Mohan L > > ______________________________________________ > 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. >
Nice thing about R is there is more than one way of doing something:> xname ip Bsent Breceived 1 a 1 0.00 0.00 2 a 2 1.43 19.83 3 a 1 0.00 0.00 4 a 2 1.00 1.00 5 b 1 0.00 2.00 6 b 3 0.00 2.00 7 b 2 2.00 0.00 8 b 2 2.00 0.00 9 b 1 24.40 22.72 10 c 1 1.00 1.00 11 c 1 2.00 1.00 12 c 1 2.00 1.00 13 c 1 90.97 15.70 14 d 0 0.00 0.00 15 d 1 30.00 17.14> require(sqldf) > sqldf('select name, sum(ip) as ip, sum(Bsent) as Bsent,+ sum(Breceived) as Breceived + from x + group by name') name ip Bsent Breceived 1 a 6 2.43 20.83 2 b 9 28.40 26.72 3 c 4 95.97 18.70 4 d 1 30.00 17.14>On Sun, Nov 7, 2010 at 8:59 AM, Mohan L <l.mohanphysics at gmail.com> wrote:> Dear All, > > I have a data frame like this: > > name ? ? ?ip ? ? ?Bsent ? ? Breceived > a ? ? ? ? ? 1 ? ? ? ?0.00 ? ? ?0.00 > a ? ? ? ? ? 2 ? ? ? 1.43 ? ? ? 19.83 > a ? ? ? ? ? 1 ? ? ? 0.00 ? ? ?0.00 > a ? ? ? ? ?2 ? ? ? ?1.00 ? ? ?1.00 > b ? ? ? ? ?1 ? ? ? ?0.00 ? ? ?2.00 > b ? ? ? ? ?3 ? ? ? 0.00 ? ? ?2.00 > b ? ? ? ? ?2 ? ? ? 2.00 ? ? ?0.00 > b ? ? ? ? 2 ? ? ? 2.00 ? ? ?0.00 > b ? ? ? ? 1 ? ? ? 24.40 ? ? 22.72 > c ? ? ? ? 1 ? ? ? 1.00 ? ? ?1.00 > c ? ? ? ? 1 ? ? ? 2.00 ? ? ?1.00 > c ? ? ? ? 1 ? ? ? 2.00 ? ? ?1.00 > c ? ? ? ? 1 ? ? ?90.97 ? ? ?15.70 > d ? ? ? ? 0 ? ? ? 0.00 ? ? ?0.00 > d ? ? ? ? 1 ? ? 30.00 ? ? ? 17.14 > > I want to sum up the similar name into one row, like : > > name ? ? ?ip ? ? ?Bsent ? ? Breceived > a ? ? ? ? ? ?6 ? ? ? ?2.43 ? ? ?20.83 > b ? ? ? ? ? ?9 ? ? ? 28.40 ? ? 26.72 > c > d > > I need help to sum up. Thanks for your time. > > > Thanks & Rg > Mohan L > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Possibly Parallel Threads
- help to merge two data frame if name matches
- Problem with which function
- Slow RAID Check/high %iowait during check after updgrade from CentOS 6.5 -> CentOS 7.2
- converting to time series object : ts - package:stats
- [LLVMdev] [llvm-commits] [PATCH] BasicBlock Autovectorization Pass