Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 88 of 196

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Feb-2021 13K+ 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 is helpful if we have a large number of levels.Example1 Live DemoConsider the below data frame −x1

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 1K+ 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 below data frame −x1 1 A 2 2 B 6 3 C 5 4 D 7Example2 Live Demoy1

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 11K+ 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 DemoM1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Feb-2021 4K+ 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 have a list called LIST and we want to multiply each value in LIST by 2 then it can be done by using the command lapply(LIST,"*",2).Example1 Live DemoList1

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 215 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 exists some ties then the output will be the first one.Example1 Live DemoConsider the below data frame −x1

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 2K+ 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 then first we need to convert them to factor first and then use the table function.Example1 Live Demox1

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 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 the function.Example1 Live DemoConsider the below data frame −x1

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 2K+ 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 of squared deviations for x can be calculated by using sum((df$x−mean(df$x))^2).Example1 Live DemoConsider the below data frame −set.seed(1021) x1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Feb-2021 1K+ 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 LIST then the names of the element in LIST can be done by using the below command: names(LIST)

Read More

How to check whether a column exists in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Feb-2021 1K+ Views

If we have very large data set then it is highly that we forget the column names, therefore, we might want to check whether a particular column exists in the data frame or not if we know the column name. For this purpose, we can use grep function that will result the column name if exists in the data frame otherwise 0. To understand how it works check out the below examples.Example1 Live DemoConsider the below data frame −Gender

Read More
Showing 871–880 of 1,958 articles
« Prev 1 86 87 88 89 90 196 Next »
Advertisements