Category Archives for "R Programming"

Jan 12

R Matrix Example

By ganpati | R Programming

8matrix_img

matrix

What it does?
It creates a matrix with the given data, number of rows and number of columns, either row wise or column wise
Syntax:
matrix ( vector of values, number of rows, number of columns, by row/column)
Example:
matrix (c(1,2,3,4,5,6), nrow=2, ncol=3, byrow=TRUE)
1 2 3
4 5 6

Jan 12

R Sample Example

By ganpati | R Programming

6sample_img

sample

What it does?
Randomly picks up a given number of values from a given vector with or without replacement
Syntax:
sample (vector, size of sample, with or without replacement)
sample (vector, size of sample, with or without replacement, probability of picking up the element of the vector)

Example:
sample( c(1:30), 10, replace = TRUE, prob = NULL)