Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 69 of 196

How to replace the outliers with 5th and 95th percentile values in R?

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

There are many ways to define an outlying value and it can be manually set by the researchers as well as technicians. Also, we can use 5th percentile for the lower outlier and the 95th percentile for the upper outlier. For this purpose, we can use squish function of scales package as shown in the below examples.Example1library(scales) x1

Read More

How to convert multiple columns into single column in an R data frame?

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

To convert multiple columns into single column in an R data frame, we can use unlist function. For example, if we have data frame defined as df and contains four columns then the columns of df can be converted into a single by using data.frame(x=unlist(df)).Example1y1

Read More

How to replace vector values less than 2 with 2 in an R vector?

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

If we have a vector that contains values with less than, equal to, and greater than 2 and the value 2 is the threshold. If this threshold value is defined for lower values and we want to replace the values that are less than 2 with 2 then pmax function can be used. For example, for a vector x, it will be done as pmax(x,2).Example1x1

Read More

How to count the number of duplicate rows in an R data frame?

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

To count the number of duplicate rows in an R data frame, we would first need to convert the data frame into a data.table object by using setDT and then count the duplicates with Count function. For example, if we have a data frame called df then the duplicate rows will be counted by using the command − setDT(df)[,list(Count=.N),names(df)].Example1y1

Read More

How to remove the first and last character in a string in R?

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

To remove the first and last character in a string, we can use str_sub function of stringr package. For example, if a word say tutorialspoint is mistakenly typed as ttutorialspointt and stored in a vector called x then to remove the first and last “t”, we can use the command str_sub(x,2,−2).Example1library(stringr) x1

Read More

How to create a categorical variable using a data frame column in R?

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

If a variable is numerical then it can be converted into a categorical variable by defining the lower and upper limits. For example, age starting from 21 and ending at 25 can be converted into a category say 21−25. To convert an R data frame column into a categorical variable, we can use cut function.Example1y1

Read More

How to find the counts of categories in categorical columns in an R data frame?

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

If we have two categorical columns in an R data frame then we can find the frequency/count of each category with respect to each category in the other column. This will help us to compare the frequencies for all categories. To find the counts of categories, we can use table function as shown in the below examples.Example1y1

Read More

How to find the frequency of values greater than or equal to a certain value in R?

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

In Data Analysis, we often need to look for less than, less than equal to, greater than, or greater than equal to values to compare them with some threshold. Sometimes we also require the frequency of these values. Therefore, we can use sum function for this purpose. For example, if a vector x has 10 integer values then to check how many of them are greater than or equal to 10, we can use the command sum(x>=10).Example1x1=5)Output[1] 83Example2x2=5)Output[1] 8Example3x3=0.25)Output[1] 38Example4x4=10)Output[1] 49Example5x5=4)Output[1] 21

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 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.Example1ID

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 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
Showing 681–690 of 1,958 articles
« Prev 1 67 68 69 70 71 196 Next »
Advertisements