This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data("Forbes2000", packages = "HSAUR") | |
##ex 1.1 | |
> tmp <- subset(Forbes2000, country==c("United States","United Kingdom","France","Germany")) | |
> by(tmp$profits, as.character(tmp$country), FUN=function(x)median(x, na.rm=T)) | |
INDICES: France | |
[1] 0.215 | |
------------------------------------------------------------------------------ | |
INDICES: Germany | |
[1] 0.245 | |
------------------------------------------------------------------------------ | |
INDICES: United Kingdom | |
[1] 0.17 | |
------------------------------------------------------------------------------ | |
INDICES: United States | |
[1] 0.26 | |
##ex 1.2 | |
> subset(Forbes2000, country=="Germany" & profits < 0, select = "name") | |
name | |
350 Allianz Worldwide | |
364 Deutsche Telekom | |
397 E.ON | |
431 HVB-HypoVereinsbank | |
500 Commerzbank | |
798 Infineon Technologies | |
869 BHW Holding | |
926 Bankgesellschaft Berlin | |
1034 W&W-Wustenrot | |
1187 mg technologies | |
1477 Nurnberger Beteiligungs | |
1887 SPAR Handels | |
1994 Mobilcom | |
##ex 1.3 | |
> summary(subset(Forbes2000, country=='Bermuda', select = "category")) | |
category | |
Insurance :10 | |
Conglomerates : 2 | |
Oil & gas operations: 2 | |
Banking : 1 | |
Capital goods : 1 | |
Food drink & tobacco: 1 | |
(Other) : 3 | |
==> Insurance | |
##ex 1.4 | |
> o <- order(Forbes2000$profits, decreasing = T) | |
> tmp <- Forbes2000[o,] | |
> tmp1 <- tmp[1:50,] | |
> plot(tmp1$sales, log(tmp1$assets), main = "Forbes2000 Top 50 Profits Company's Sales vs Assets", xlab = "Sales", ylab = "log(Assets)") | |
> text(tmp1$sales, log(tmp1$assets), abbreviate(tmp1$country)) | |
##ex 1.5 | |
> by(Forbes2000$sales, as.character(Forbes2000$country), FUN = function(x) mean(x, na.rm = T)) | |
> tmp <- Forbes2000[Forbes2000$profits>5, c("name","country")] | |
> summary(tmp$country) |