Nizamuddin Siddiqui has Published 2307 Articles

How to extract the factor levels from factor column in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:21:43

9K+ Views

To extract the factor levels from factor column, we can simply use levels function. For example, if we have a data frame called df that contains a factor column defined with x then the levels of factor levels in x can be extracted by using the command levels(df$x). This extraction ... Read More

How to use column index instead of column name while using group_by of dplyr in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:21:06

764 Views

When we use group_by function of dplyr package, we need to pass the column name(s) that are categorical in nature. If we want to use the index of the same column(s) then group_by_at function needs to be used, where we can pass the column index as the argument.Example1 Live DemoConsider the ... Read More

How to find the sum of rows, columns, and total in a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:20:45

9K+ Views

To find the sum of row, columns, and total in a matrix can be simply done by using the functions rowSums, colSums, and sum respectively. The row sums, column sums, and total are mostly used comparative analysis tools such as analysis of variance, chi−square testing etc.Example1 Live DemoM1Read More

How to find the number of unique values in a vector by excluding missing values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:13:10

837 Views

If there exist missing values in an R vector then it is counted as a unique value in the vector, therefore the extraction of unique values cannot be done directly. For this purpose, we need to use unique with na.omit function. For example. If we have a vector called x ... Read More

How to multiply all values in a list by a number in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:12:55

3K+ Views

To multiply all values in a list by a number, we can use lapply function. Inside the lapply function we would need to supply multiplication sign that is * with the list name and the number by which we want to multiple all the list values. For example, if we ... Read More

How to create a column with largest size string value in rows in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:10:44

93 Views

To create a column with largest size string value in rows, we can use apply function and define the size of the string for the largest value by creating a function as shown in the below examples. If the number of characters in all the columns are same or there ... Read More

How to create a frequency table in R that includes zero frequency for value that are not available?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:10:29

1K+ Views

When we use table function in R, the output shows the frequency of values that are available in the vector or in column of the data frame. If we want to create the table with the frequency zero for values that are not part of the vector or the column ... Read More

How to find the correlation of one variable with all the other variables in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:09:00

3K+ Views

To find the correlation of each variable with remaining variables, we can create a correlation matrix but for the correlation of only one variable with all the other variables we need to define the columns inside the cor function. The output will represent the columns and rows as passed inside ... Read More

How to find the sum of squared deviations for an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:08:45

992 Views

The sum of squared deviations is the total of the square of difference between each value and the mean. To find this value, we need to create the formula in R platform. For example, if we have a data frame called df that contains a column x then the sum ... Read More

How to change the name of variables in a list in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Feb-2021 12:02:47

654 Views

The name of variables in a list are actually the list elements. These elements can be either named or unnamed. The naming can be done with the help of names function and renaming can be done in the same way as well. For example, if we have a list called ... Read More

Advertisements