# Inference for a Single Mean with R

The R scan function allows you to enter data without typing commas. In the case below, the values were not actually typed but inserted with cut and paste. The "24:" prompt means R has received 23 numbers and is waiting for the 24th. Hit RETURN to cease data entry. The data represent the speeds of cars measured in an area where the speed limit is 30 miles per hour.

```> speeds = scan()
1:    29   34   34   28   30   29   38   31   29   34   32   31   27   37   29   26   24   34   36   31   34   36   21
24:

> stem(speeds)

The decimal point is 1 digit(s) to the right of the |

2 | 14
2 | 6789999
3 | 0111244444
3 | 6678

> stem(speeds, scale=2)

The decimal point is at the |

20 | 0
22 |
24 | 0
26 | 00
28 | 00000
30 | 0000
32 | 0
34 | 00000
36 | 000
38 | 0

> summary(speeds)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
21.00   29.00   31.00   31.04   34.00   38.00

> t.test(speeds, mu=30, alternative="greater", conf.level=0.90)

One Sample t-test

data:  speeds
t = 1.1781, df = 22, p-value = 0.1257
alternative hypothesis: true mean is greater than 30
90 percent confidence interval:
29.87323      Inf
sample estimates:
mean of x
31.04348

```

Note that a single command returns both a hypothesis test and a confidence interval. The confidence level must be specified as a number between 0 and 1. Another alternative for alternative is "less". Leaving it out gives a two-sided test/interval. The default mu is 0 and the default confidence level 95%=0.95. Here we do not reject the null that the average speed is equal to the speed limit. So, people do not appear to be speeding on average. Left as an exercise is the possibly more interesting question of what proportion are speeding.