The power of R, pt I

August 1, 2006

A small illustration culled from the R intro…

# 30 elements in each array..
# ..a salary and an Aussie state
incomes <- c(60, 49, 40, 61, 64, 60,
  59, 54, 62, 69, 70, 42, 56,
  61, 61, 61, 58, 51, 48, 65,
  49, 49, 41, 48, 52, 46, 59, 46, 58, 43)
state <- c(“tas”, “sa”,  “qld”, “nsw”,
  “nsw”, “nt”,  “wa”,  “wa”,  “qld”,
  “vic”, “nsw”, “vic”, “qld”, “qld”,
  “sa”,  “tas”, “sa”,  “nt”,  “wa”, 
  “vic”, “qld”, “nsw”, “nsw”, “wa”, 
  “sa”,  “act”, “nsw”, “vic”, “vic”, “act”)
                 
# Categorise the states and categorise the incomes
# into buckets using cut(). Then use table() to
# generate a table of counts for each category
# combination…
statef <- factor( state)
incomef <- factor( cut( incomes, breaks = 35 + 10*(0:7)))
table( incomef, statef)


         statef
incomef   act nsw nt qld sa tas vic wa
  (35,45]   1   1  0   1  0   0   1  0
  (45,55]   1   1  1   1  2   0   1  3
  (55,65]   0   3  1   3  2   2   2  1
  (65,75]   0   1  0   0  0   0   1  0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s