w4

Run Settings
LanguageC
Language Version
Run Command
WEEK 4: A) various operations on vectors X <- c(1, 4, 5, 2, 6, 7) print('using c function') print(X) Output: [1] "using c function" [1] 1 4 5 2 6 7 Y <- seq(1, 10, length.out = 5) print('using seq() function') print(Y) Output: [1] "using seq() function" [1] 1.00 3.25 5.50 7.75 10.00 B) Finding the sum and average of given numbers using arrays. X <-1:5 Y <-6:10 X Y X+Y Output: X [1] 1 2 3 4 5 Y [1] 6 7 8 9 10 X+Y [1] 7 9 11 13 15 Another Method: SUM: list = c(2, 4, 4, 4, 5, 5, 7, 9) print(sum(list)) Output: 40 AVERAGE: print(mean(list)) output 5 C) To display elements of list in reverse order. ("c", "b", "a") result = rev(x) print(result) Output: [[1]] [1] "a" [[2]] [1] "b" [[3]] [1] "c" D) Finding the minimum and maximum elements in the array. x <- c(8, 2, 5, 4, 9, 6, 54, 18) range(x) Output: 2 54
Editor Settings
Theme
Key bindings
Full width
Lines