Is
TAB3 <- as.data.frame(with(TAB1, tapply(Number, Name, sum)))
colnames(TAB3) <- c("Name_singular", "Sum")
what you are looking for?
-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Michael Graber
Sent: 25 October 2005 09:45 PM
To: R-Mailingliste
Subject: [R] data.frame-question
Dear R-List,
I am very new to R and programming itself, so my question may be easy to
answer for you.
I tried a lot and read through the manuals, but I still have the following
problem:
I have 2 data-frames:
Number<-as.numeric (Number)
Name<-as.character (Name)
TAB1<-data.frame (Name,Number)
- it looks like this:-
Name Number
A 2
A 3
A 6
B 8
B 12
B 7
C 8
D 90
E 12
E 45
...
Name_singular<-as.character (Name_singular) TAB2<-data.frame
(Name_singular)
# it looks like this:
Name_singular
A
B
C
D
E
-My result should be a data-frame, where the first column is Name_singular
and the second column should be the sum of the numbers where Name
==Name_singular.- For example:
TAB3:
Name_singular Sum
A 11
B 27
...
- I tried it with for-loops, but I think there must be an easier way.- I
would be very grateful for your help,
Michael Graber
______________________________________________
R-help@stat.math.ethz.ch mailing list
stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
R-project.org/posting-guide.html
********************
Nedbank Limited Reg No 1951/000009/06
Directors: WAM Clewlow (Chairman) Prof MM Katz (Vice-chairman) ML Ndlovu
(Vice-chairman) TA Boardman (Chief Executive)
CJW Ball MWT Brown RG Cottrell BE Davison N Dennis (British) MA Enus-Brey
Prof B de L Figaji RM Head (British)
RJ Khoza JB Magwaza ME Mkwanazi JVF Roberts (British) CML Savage GT Serobe
JH Sutcliffe (British)
Company Secretary: GS Nienaber 16.08.2005
This email and any accompanying attachments may contain confidential and
proprietary information. This information is private and protected by law and,
accordingly, if you are not the intended recipient, you are requested to delete
this entire communication immediately and are notified that any disclosure,
copying or distribution of or taking any action based on this information is
prohibited.
Emails cannot be guaranteed to be secure or free of errors or viruses. The
sender does not accept any liability or responsibility for any interception,
corruption, destruction, loss, late arrival or incompleteness of or tampering or
interference with any of the information contained in this email or for its
incorrect delivery or non-delivery for whatsoever reason or for its effect on
any electronic device of the recipient.
If verification of this email or any attachment is required, please request a
hard-copy version.
********************
[[alternative HTML version deleted]]