[R] Finding a mean value of a variable holding a dummy variablefixed

Daniel Malter daniel at umd.edu
Mon Mar 31 04:05:14 CEST 2008


The mean problem can be solved with

president=c("Johnson","Johnson","Johnson","Johnson","Johnson","Johnson","Nix
on","Nixon","Nixon","Nixon","Nixon","Nixon")
approval=seq(1:12)
tapply(approval,president,mean)

For the other, I will try to come back. But I am sure somebody will be
faster than I.

Cheers,
Daniel 


-------------------------
cuncta stricte discussurus
-------------------------

-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Alexander Ovodenko
Gesendet: Sunday, March 30, 2008 9:47 PM
An: r-help at r-project.org
Betreff: [R] Finding a mean value of a variable holding a dummy
variablefixed

I have time-series data on approval ratings of British Prime Ministers.  The
prime ministers dating from MacMillan onward till today are coded as dummy
variables and the approval ratings are entered for each month.  I want to
know the mean value of the approval rating of each Prime Minister in the
dataset and the approval rating during his/her first month and last month as
PM.  What R code should I enter for these data?  In other words, I want hold
the dummy corresponding to each Prime Minister fixed at value one and know
the first rating that PM has, the last rating s/he has, and the mean rating
s/he has.  Thanks.

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



More information about the R-help mailing list