Built-in Function in R Programming Language
Table of Content:
Simple examples of in-built functions are seq(), mean(), max(), sum(x)and paste(...) etc. They are directly called by user written programs. You can refer most widely used R functions.
# Create a sequence of numbers from 10 to 44. print(seq(10,44)) # Find mean of numbers from 20 to 82. print(mean(20:82)) # Find sum of numbers frm 40 to 68. print(sum(40:68))
When we execute the above code, it produces the following result ?
> # Create a sequence of numbers from 32 to 44. > print(seq(10,44)) [1] 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 [28] 37 38 39 40 41 42 43 44 > > # Find mean of numbers from 25 to 82. > print(mean(20:82)) [1] 51 > > # Find sum of numbers frm 41 to 68. > print(sum(40:68)) [1] 1566 > # Create a sequence of numbers from 10 to 44. > print(seq(10,44)) [1] 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 [28] 37 38 39 40 41 42 43 44 > > # Find mean of numbers from 20 to 82. > print(mean(20:82)) [1] 51 > > # Find sum of numbers frm 40 to 68. > print(sum(40:68)) [1] 1566 >
Another Examples
x <- 1:10 x sum(x) mean(x) x[c(2,3)] <- NA x mean(x, na.rm = TRUE)
If you will run the above code you will get the below output
> x <- 1:10 > x [1] 1 2 3 4 5 6 7 8 9 10 > sum(x) [1] 55 > mean(x) [1] 5.5 > x[c(2,3)] <- NA > x [1] 1 NA NA 4 5 6 7 8 9 10 > mean(x, na.rm = TRUE) [1] 6.25