A main window will open and within it will be another window (called the "R console"). This second window will display some introductory text and at the end will be a ">" prompt (without quotes).
>
q()
> x
<- 3
>
ls()
>
rm(x)
3. Data
Manipulation
Suppose we want to enter the following set of data into R
Name |
Age |
Number of siblings |
Bob |
27 |
2 |
Sue |
33 |
1 |
Bill |
21 |
0 |
John |
56 |
4 |
For now, we will enter the data directly by hand. This is ok for small datasets, but we will use other methods of data input later on. Type
> name
<- c("Bob", "Sue", "Bill", "John")
>
name
> age <- c(27, 33, 21, 56)
>
num.siblings <- c(2, 1, 0, 4)
> mean(age)
> median(age)
> summary(age)
>
sum(age)
>
num.siblings^2
> max(num.siblings)
> num.siblings + 2
> age +
num.siblings
> x
<- 1:20
> x <- c(1:20)
> x <- seq(1:20)
> 5:20
> seq(from=5, to=20)
>
seq(along=5:20)
> seq(5:20)
4. Getting
help
>
help(functionname)
Exercise: Find out what the commands "sort" and "rep" do.
5. Further
exercises
Make sure you have read the material above. You will need it to perform this exercise.
Brief background on data: Climatologists
interested
in flooding gather statistics on the daily rainfall in various cities. The
following
data set gives the maximum daily rainfall (in inches) for the years 1941
to
1970 in
Data:
1.88 2.23 2.58 2.07 2.94 2.29 3.14 2.14 1.95
2.51
2.86 1.48 1.12
2.76 1.48 1.12 2.76 1.50 2.99 3.48 2.12 4.69 2.29
2.12
(c) Find the variance and the standard deviation. (Hint 1: the standard deviation is the square root of the variance; Hint 2: the commands "var" and "sqrt" may be useful - use the help function to find out what they do)
> x
<- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
> x
<- 1:10
(b) Write down the form of the command "rep" that takes "x" as an input and outputs the following
> [1] 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
(c) Write down the form of the command "rep" that takes "x" as input and outputs the following"
> [1] 1
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
10