Here is a typical data analysis on R. I'm a baseball fan and I'm interested in the wins and losses for the current Major League teams and how these wins and losses are related to the runs scored and runs allowed.
In Excel, I create a dataset that contains the wins, losses, runs scored, and runs allowed for all 30 teams. Here is the first 4 rows of the dataset.
I save this dataset as "baseball2008.txt" -- text, tab-delimited format. I save this file in a folder called "eda" and I make this the current R working directory so R will find this file.
Here is my analysis:
# read the datafile into R
# attach the data to make the variable names available in R
# compute the winning proportion for all teams
# what was the largest winning proportion?
# which team had the largest winning proportion?
 Chicago Cubs
# for each team, compute the number of runs scored per game
# construct a stemplot of the runs scored per game
# (I'm assuming you have the aplpack package installed)
1 | 2: represents 1.2
leaf unit: 0.1
1 s | 7
4 3. | 889
7 4* | 011
8 t | 2
12 f | 4555
(6) s | 666667
12 4. | 88899
7 5* | 00011
2 f | 45
# (sorry the display got messed up when I put it on this blog)
# you get a similar display by using a histogram
# there are two teams who stand out with respect to runs scored
 Texas Chicago Cubs
# what is the average number of runs per game scored by a team?
# do American League teams score more than National League teams?
# there is an interesting relationship between a team's winning
# proportion and the number of runs scored and runs allowed
# the relationship is log(W/L) = k log(RS/RA)
# where k is typically near 2
# we'll compute log(W/L), log(RS/RA)
# and fit a least-squares line -- we'll see if the slope is close to 2
lm(log.WL ~ log.RR)
# here we see the slope is 1.84 which relatively close to 2