x
that consists of the integers 1 through 12, inclusive. Do the following:x
> [1] 1 2 3 4 5 6 7 8 9 10 11 12
x
x
> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
.
”.pres.txt
, read the file by using read.table()
, specify the column names and missing value, and print first 6 rows out as follows.col.names
: specify column namessep
: specify the delimiter, default: white spacena.strings
- how missing values are recordedhead()
- show the first n observations, default: first 6 rows> name startyear endyear party
> 1 Washington 1789 1797 NP
> 2 Adams 1797 1801 F
> 3 Jefferson 1801 1809 DR
> 4 Madison 1809 1817 DR
> 5 Monroe 1817 1825 DR
> 6 Adams 1825 1829 DR
pres2.txt
, read the file by using read.fwf()
, specify the column names, skip first 9 rows, and print first 6 rows out as follows.col.names
: specify column namesskip
: number of lines to skip before readingwidths
- width of characters of each column, use 17, 8, 8, 4
here.head()
- show the first n observations, default: first 6 rows> name start end days
> 1 John F. Kennedy 01/20/61 11/22/63 1036
> 2 Lyndon B. Johnson 11/22/63 01/20/69 1886
> 3 Richard Nixon 01/20/69 08/09/74 2027
> 4 Gerald Ford 08/09/74 01/20/77 895
> 5 Jimmy Carter 01/20/77 01/20/81 1461
> 6 Ronald Regan 01/20/81 01/20/89 2922
X
that looks like\[ \begin{pmatrix} 1 & 2 & 3 & 4 & 5 \\ 6 & 7 & 8 & 9 & 10 \\ 11 & 12 & 13 & 14 & 15 \\ 16 & 17 & 18 & 19 & 20 \end{pmatrix} \]
X
> [,1] [,2] [,3] [,4] [,5]
> [1,] 1 2 3 4 5
> [2,] 6 7 8 9 10
> [3,] 11 12 13 14 15
> [4,] 16 17 18 19 20
8
to 100
. Print X
.> [,1] [,2] [,3] [,4] [,5]
> [1,] 1 2 3 4 5
> [2,] 6 7 100 9 10
> [3,] 11 12 13 14 15
> [4,] 16 17 18 19 20
1
’s. Print X
.> [,1] [,2] [,3] [,4] [,5]
> [1,] 1 1 1 1 1
> [2,] 6 7 100 9 10
> [3,] 11 12 13 14 15
> [4,] 16 17 18 19 20
19, 14, 9, 4
. Print X
.> [,1] [,2] [,3] [,4] [,5]
> [1,] 1 1 1 19 1
> [2,] 6 7 100 14 10
> [3,] 11 12 13 9 15
> [4,] 16 17 18 4 20
cars
(You don’t have to specify the package, just use data(cars)
.) to do the following.> [1] 50 2
> [1] 2
> [1] 120
s
. Print s
, and find its dimension, minimum, and maximum.> NULL
> [1] 4
> [1] 25
d
. Print d
, and find its dimension, minimum, and maximum.> NULL
> [1] 2
> [1] 120
> $cylinder
> [1] 4
>
> $mpg
> [1] 22.8 24.4 33.9
>
> $car.brand
> [1] "Datsun" "Mercedes" "Toyota"
>
> $is.German
> [1] FALSE TRUE FALSE