No answer required.
a <- 9
a
## [1] 9
is.numeric(a)
## [1] TRUE
The output of TRUE
tells us that yes, indeed, a
is a numeric variable.
b <- 8
c <- sqrt(a * b)
c
## [1] 8.485281
is.numeric(c)
## [1] TRUE
No answer required.
round(c, digits = 3)
## [1] 8.485
fives <- seq(from = 0, to = 40, by = 5)
fives
## [1] 0 5 10 15 20 25 30 35 40
countries <- c("Australia", "Singapore", "China", "New Zealand", "Japan", "India")
countries
## [1] "Australia" "Singapore" "China" "New Zealand" "Japan"
## [6] "India"
pop.millions <- c(25, 5, 1433, 4, 126, 1366)
matrix.name <- cbind(fives, pop.millions)
## Warning in cbind(fives, pop.millions): number of rows of result is not a
## multiple of vector length (arg 2)
matrix.name
## fives pop.millions
## [1,] 0 25
## [2,] 5 5
## [3,] 10 1433
## [4,] 15 4
## [5,] 20 126
## [6,] 25 1366
## [7,] 30 25
## [8,] 35 5
## [9,] 40 1433
Note that here, because the two vectors are not the same length, some of the pop.millions
values are repeated.
dim(matrix.name) # check dimensions
## [1] 9 2
nrow(matrix.name) # check number of rows
## [1] 9
ncol(matrix.name) # check number of columns
## [1] 2
countries.df <- data.frame(countries, pop.millions)
countries.df
## countries pop.millions
## 1 Australia 25
## 2 Singapore 5
## 3 China 1433
## 4 New Zealand 4
## 5 Japan 126
## 6 India 1366
my.list <- list(c = c, fives = fives, countries =countries,
countries.df = countries.df)
my.list
## $c
## [1] 8.485281
##
## $fives
## [1] 0 5 10 15 20 25 30 35 40
##
## $countries
## [1] "Australia" "Singapore" "China" "New Zealand" "Japan"
## [6] "India"
##
## $countries.df
## countries pop.millions
## 1 Australia 25
## 2 Singapore 5
## 3 China 1433
## 4 New Zealand 4
## 5 Japan 126
## 6 India 1366
names(my.list)
## [1] "c" "fives" "countries" "countries.df"
library(MASS)
?MASS # or
help(MASS)
These notes have been prepared by Rupert Kuveke and Amanda Shaker. The copyright for the material in these notes resides with the authors named above, with the Department of Mathematics and Statistics and with La Trobe University. Copyright in this work is vested in La Trobe University including all La Trobe University branding and naming. Unless otherwise stated, material within this work is licensed under a Creative Commons Attribution-Non Commercial-Non Derivatives License BY-NC-ND.