N1 <- c(100,200,300,500,10,20,25)
print(N1)
## [1] 100 200 300 500 10 20 25
mean(N1)
## [1] 165
maxn1 = max(N1)
maxn1
## [1] 500
which.max(N1)
## [1] 4
show(N1)
## [1] 100 200 300 500 10 20 25
N1[c(3,6)] <- c(700,800)
print(N1)
## [1] 100 200 700 500 10 800 25
C1 <- c("Stop","the world.","I want to get off")
C1
## [1] "Stop" "the world." "I want to get off"
length(C1)
## [1] 3
print(C1[2])
## [1] "the world."
C2 <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
C2
## [1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
C2[3:8]
## [1] "Mar" "Apr" "May" "Jun" "Jul" "Aug"
C2[-4:-1]
## [1] "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
N2 <- seq(from = 3, to = 30, by = 3)
show(N2)
## [1] 3 6 9 12 15 18 21 24 27 30
N2[11] <- 33
N2
## [1] 3 6 9 12 15 18 21 24 27 30 33
str(N2)
## num [1:11] 3 6 9 12 15 18 21 24 27 30 ...
show(N2)
## [1] 3 6 9 12 15 18 21 24 27 30 33
By using the Structure Function (str) you are given more information then the Show Function (show). The Structure Function tells you the type of values in the vector and also tells you how many values are in the vector which the Show Function does not give.
N3 <- c(1, 20, 21, 45, 80, NA, 40, NA)
N3
## [1] 1 20 21 45 80 NA 40 NA
sum(N3)
## [1] NA
sum(N3, na.rm = TRUE)
## [1] 207