Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 45 of 196

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ 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 purpose, we can use select_if function of dplyr package along with the length function as shown in the below examples.Example1Consider the below data frame −> x1 x2 x3 x4 df1 df1Output   x1      x2          x3    x4 1  a  -0.18404831  0.1082741 2 2  b  -0.28597330 ...

Read More

How to extract the split string elements in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

To split string vector elements, we can use strsplit function. And if we want to extract the string elements after splitting then double and single square brackets will be used. The double square bracket will extract the string vector element and the single square will extract the element after splitting. Check out the examples to understand how it works.Example1> x1 x1Output[1] "Tutorialspoint is an E-learning platform" [2] "E-learning is important" [3] "It helps in learning and growing at a faster rate"Example> x1 x1Output[[1]] [1] "Tutorialspoint" "is" "an" "E-learning" [5] "platform" [[2]] [1] "E-learning" "is" "important" [[3]] [1] "It" ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ 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 the vector or column of the data frame inside the tolower function as shown in the below examples.Example1Consider the below data frame −> x1 y1 df1 df1Output   x1     y1 1  C  -0.1036851 2  C  -0.6176530 3  B   0.5763786 4  A   0.1943794 5  C   1.1196470 6 ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 194 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 than 4 then we might want to subset columns having less than four categories. This could be required in situations when we want to subset the data biasedly or have some predefined data characteristics that allows this change. The subset of such columns can be done with the help of ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 8K+ 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 example, if we have a table called T then to convert it into a data frame format we can use the command as.data.frame(T).Example1> x1 x1Output[1] 2 0 2 3 2 3 1 2 1 4 0 0 4 4 1 3 1 2 1 3 2 3 2 1 4 ...

Read More

How to remove rows using character column that has elements of size less than 3 in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 615 Views

To find the number of characters in character vector elements or the elements in a character column of an R data frame, we can use nchar function. Therefore, if we want to remove rows that has elements of size less than 3 we would need to use the same function and then subset function will be used to remove the required rows as shown in the below examples.Example1Consider the below data frame −> x1 x2 df1 df1Output    x1   x2 1  India 1 2  India 2 3  UK    1 4  UK    2 5  China 1 6  India ...

Read More

How to add a new column to a data frame using mutate in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

The mutate function of dplyr package in R can help us to add a new column to a data frame and the benefit of using mutate is that we can decide the position of the new column during the addition. For example, if we have a data frame called df that contains three columns say x, y, a then we can add a new column say z after y using mutate function. To understand how it can be done, check out the below examples.Example1Consider the below data frame −> x1 x3 df1 df1Output   x1 x3 1  2  3 2  1 ...

Read More

How to preserve data frame structure after applying a function in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 416 Views

When we apply a function using apply family, by default the output is not in the form of a data frame. If we want to preserve the original data frame structure then we need to set the application of the apply family by setting it to the original data frame with single brackets and no arguments as shown in the below examples.Example1Consider the below data frame −> df1 df1Output   x1 x2 1  4 2 2  6 2 3  5 2 4  2 1 5  8 4 6  7 2 7  5 3 8 ...

Read More

How to convert a binary matrix to logical matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

A binary matrix contains values such as Yes or NO, 1 or 0, or any other two values that represents opposite mostly and the globally accepted logical values are FALSE and TRUE. Therefore, to convert a binary matrix to logical matrix, we can use ifelse function and convert the one category of binary variable to appropriate logical value and for the rest returns the left-out value. This is a very easy task in R, check out the below examples to understand how it can be done.Example1> M1 M1Output[, 1] [, 2] [1, ] "No" "Yes" [2, ] "No" "No" [3, ...

Read More

How to find the unique rows in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

A unique row in an R data frame means that all the elements in that row are not repeated with the same combination in the whole data frame. In simple words, we can say that if we have a data frame called df that contains 3 columns and 5 rows then all the values in a particular row are not repeated for any other row. The search of this type of rows might be required when we have a lot of duplicate rows in our data set. To do this, we can use group_by_all function of dplyr package as shown ...

Read More
Showing 441–450 of 1,958 articles
« Prev 1 43 44 45 46 47 196 Next »
Advertisements