Nizamuddin Siddiqui has Published 2307 Articles

How to find the frequency table for factor columns in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:57:39

609 Views

If we have factor columns in an R data frame then we want to find the frequency of each factor level for all the factor columns. This can be done with the help of sapply function with table function. For example, if we have a data frame called df that ... Read More

How to convert a vector to data frame in R by defining number of columns?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:55:19

168 Views

If we have a vector where alternate values may create a tabular form then we might want to convert the vector into a data frame. For this purpose, we first need to convert the vector into a matrix with appropriate number of columns/rows and then read it as a data ... Read More

How to extract the first digit from a character column in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:53:11

751 Views

If we have a character column in the data frame that contains string as well as numeric values and the first digit of the numeric values has some meaning that can help in data analysis then we can extract those first digits. For this purpose, we can use stri_extract_first function ... Read More

How to change the position of missing values to the end of data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:48:05

82 Views

Most of the times we need to deal with missing values in data science projects and these missing values can be occurred at any position. We might want to change the position of these missing values and send them to the end of the columns in the data frame. This ... Read More

How to convert an old data frame to new data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:42:17

426 Views

To convert an old data frame to a new data frame, we can simply set the new name. For example, if we have a data frame called df and want to convert it to a new one let’s say df_new then it can be done as df_new x1 x2 df1 ... Read More

How to remove rows in an R data frame column that has duplicate values greater than or equal to a certain number of times?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:39:16

271 Views

To remove rows from the data frame that duplicate values greater than a certain number of times, we can create a subset for rows having duplicate values less than the certain number of times. For this purpose, we first need to extract the rows and then subset the data frame ... Read More

How to find the number of numerical columns in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:36:54

867 Views

We know that a data frame can contain any type of columns such as numerical, character, logical, factor, etc. And if a data frame contains multiple type of columns then we might want to find the number of columns for each type or of one type say numerical. For this ... Read More

How to convert the character values in an R data frame column to lower case?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:32:19

2K+ Views

The character values can be stored in uppercase, lowercase, or a mixture of the two. If we have values that are either in uppercase or the mixture of lower and upper then we can convert those character values to only lowercase by using tolower function. We simply need to pass ... Read More

How to subset columns that has less than four categories in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:28:48

83 Views

If column is categorical then there can be at least two categories and there is no limit for the total number of categories but it will also depend on the total number of cases. If we have a data frame that contain some categorical columns having more or less categories ... Read More

How to create a frequency table in data frame format in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:23:24

7K+ Views

To create a frequency table in R, we can simply use table function but the output of table function returns a horizontal table. If we want to read the table in data frame format then we would need to read the table as a data frame using as.data.frame function. For ... Read More

Advertisements