Nizamuddin Siddiqui has Published 2307 Articles

How to separate string and a numeric value in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:43:49

910 Views

To separate string and a numeric value, we can use strplit function and split the values by passing all type of characters and all the numeric values. For example, if we have a data frame called df that contains a character column Var having concatenated string and numerical values then ... Read More

How to find mean for x number of rows in a column in an R matrix?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:41:44

96 Views

To find the mean for x number of rows in a column, we can use colMeans function by accessing the column and providing the number of rows. For example, if we have a matrix called M that contains 20 rows and 5 columns then we can find the mean of ... Read More

How to divide each value in a data frame by column total in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:37:36

2K+ Views

To divide each value in a data frame by column total, we can use apply function and define the function for the division. For example, if we have a data frame called df that contains five columns then we can divide each value of these columns by column total using ... Read More

How to find the sum by two factor columns in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:31:47

1K+ Views

To find the sum by two factor columns, we can use aggregate function. This is mostly required when we have frequency/count data for two factors. For example, if we have a data frame called df that contains two factor columns say f1 and f2 and one numerical column say Count ... Read More

How to convert an array into a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:25:25

3K+ Views

To convert an array into a matrix in R, we can use apply function. For example, if we have an array called ARRAY that contains 2 array elements then we can convert this array into a single matrix using the command apply(ARRAY, 2, c). We need to understand the dimension ... Read More

How to add name to data frame columns in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:18:47

1K+ Views

A data frame can be created by using data.frame function but in this case R generates the column names using the values we pass for the data. For example, if we pass a probability distribution as shown in the below examples then its name will be there. If we want ... Read More

How to find the position of odd numbers in an R vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:13:00

2K+ Views

To find the position of odd numbers in an R vector, we can find the position of values that are divisible by 2 with the help of which function. For example, if we have a vector called x then we can find the position of odd numbers using the command ... Read More

How to generate random numbers with sequence and store in a data frame column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 12:49:01

736 Views

To generate random numbers with sequence and storing them in a data frame column, we can use sample function with seq. For example, if we want to create a data frame column having random sequence of values of size 50 between 1 to 100 by considering every tenth value then ... Read More

How to create a random vector for a range of values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 12:44:30

2K+ Views

To create a random vector for a range of values, we can use sample function. We just need to pass the range and the sample size inside the sample function. For example, if we want to create a random sample of size 20 for a range of values between 1 ... Read More

How to create a table for the number of unique values in list of vectors in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 12:42:30

145 Views

To create a table for the number of unique values in list of vectors, we can use mtabulate function of qdapTools package. For example, if we have a list of vectors say LIST that contains some vectors then the table for the number of unique values in the vectors of ... Read More

Advertisements