## R Programming: Extract the Five of the Levels of Factor Created From a Random Sample From the Letters

R Programming: Extract the five of the levels of factor created from a random sample from the LETTERS L = sample(LETTERS,size=50,replace=TRUE) print("Original data:") print(L) f = factor(L) print("Original factors:") print(f)…

## R Programming: Create an Ordered Factor From Data Consisting of the Names of Months

R Programming: Create an ordered factor from data consisting of the names of months mons_v = c("March","April","January","November","January", "September","October","September","November","August","February", "January","November","November","February","May","August","February", "July","December","August","August","September","November","September", "February","April") print("Original vector:") print(mons_v) f = factor(mons_v) print("Ordered factors of…

## R Programming: Change the First Level of a Factor With Another Level of a Given Factor

R Programming: Change the first level of a factor with another level of a given factor v = c("a", "b", "a", "c", "b") print("Original vector:") print(v) f = factor(v) print("Factor…

## R Programming: Find Row and Column Index of Maximum and Minimum Value in a Given Matrix

R Programming: Find row and column index of maximum and minimum value in a given matrix m = matrix(c(1:16), nrow = 4, byrow = TRUE) print("Original Matrix:") print(m) result =…

## R Programming: Convert a Given Matrix to a List of Column-Vectors

R Programming: Convert a given matrix to a list of column-vectors x = matrix(1:12, ncol=3) print("Original matrix:") print(x) print("list from the said matrix:") l = split(x, rep(1:ncol(x), each = nrow(x)))…

## R Programming: Create a Matrix From a List of Given Vectors

R Programming: Create a matrix from a list of given vectors l = list() for (i in 1:5) l[[i]] <- c(i, 1:4) print("List of vectors:") print(l) result = do.call(rbind, l)…

## R Programming: Create a Matrix Taking a Given Vector of Numbers as Input and Define the Column and Row Names

R Programming: Create a matrix taking a given vector of numbers as input and define the column and row names row_names = c("row1", "row2", "row3", "row4") col_names = c("col1", "col2",…

## R Programming: Create an 3 Dimensional Array of 24 Elements Using the Dim() Function

R Programming: Create an 3 dimensional array of 24 elements using the dim() function v = sample(1:5,24,replace = TRUE) dim(v) = c(3,2,4) print("3-dimension array:") print(v) output [1] "3-dimension array:" ,…

## R Programming: Extract All Elements Except the Third Element of the First Vector of a Given List

R Programming: Extract all elements except the third element of the first vector of a given list list1 = list(g1 = 1:10, g2 = "R Programming", g3 = "HTML") print("Original…

## R Programming: Create a List of Random Numbers in Normal Distribution and Count Occurrences of Each Value

R Programming: Create a list of random numbers in normal distribution and count occurrences of each value n = floor(rnorm(1000, 50, 100)) print('List of random numbers in normal distribution:') print(n)…