Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 24 of 196

How to replace words in a dichotomous column for an R data frame with numbers?\\n

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 476 Views

A dichotomous column can be represented by words such as Yes/No, Good/Bad, Right/Wrong etc. To replace such words with number, say 1 and 0 we can use ifelse function.For example, if we have a data frame called df that contains a column Binary with Yes and No values then we can replace Yes with 1 and No with 0 by using the below command −df$Binary

Read More

How to create a histogram for uniform data in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 399 Views

To create a histogram for uniform data in R, we can simply use hist function but the bars size may vary even if the frequency is same. Therefore, for this purpose, we need to define the breaks as shown in the below example.ExampleTo create a histogram for uniform data in R, use the code given below −hist(1:6)OutputIf you execute the above given code, it generates the following output −To create a histogram for uniform data in R, use the code given below −hist(1:8) OutputIf you execute the above given code, it generates the following output −To create a histogram for ...

Read More

How to find the smallest number in an R data frame column excluding values zero or less?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 3K+ Views

To find the smallest number in an R data frame column excluding values zero or less, we can use min function along with subsetting of values greater than 0 through single square brackets.For example, if we have a data frame called df that contains a column say X then the smallest number excluding values zero or less can be found by using the below command −min(df[df$X>0,1])Example 1Following snippet creates a sample data frame −x

Read More

How to find the dot product of two matrices in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 2K+ Views

To find the dot product of two matrices in R, we can use dot function of geometry package.For Example, if we have two matrices say matrix1 and matrix2 then we can use the dot product of these two matrices by using the below given command −dot(matrix1,matrix2)Example 1Following snippet creates a sample matrix −M1

Read More

How to create a plot of empirical distribution in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 3K+ Views

The empirical distribution can be found by using the function ecdf and if we want to create a plot of empirical distribution then plot function will be used.For example, if we have a vector called X then plot of empirical distribution can be created by using the below command −plot(ecdf(X))Example 1To create a plot of empirical distribution in R, use the code given below −x

Read More

How to create sequential index value for binary column assigning 0 to FALSE values in data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 148 Views

To create sequential index value for binary column assigning 0 to FALSE values in data.table object in R, we can follow the below steps: −First of all, create a data.table object with binary column.Then, use rle function along with sequence and lengths function to create sequential index column.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) x

Read More

How to deal with glm.fit error “NA/NaN/Inf” for logistic regression model in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 5K+ Views

When we create a general linear model for logistic regression model, we need to specify the distribution family as binomial. The error “NA/NaN/Inf” occurs when we do not specify the distribution family. Hence, family="binomial" needs to be used inside glm function while creating the logistic regression model.Example 1Following snippet creates a sample data frame −iv1

Read More

How to separate first text value and the remaining text in R data frame column values?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 242 Views

To separate a first text value and the remaining text in R data frame column values, we can follow the below steps −First of all, create a data frame.Then, use str_split function from stringr package to separate first text value and the remaining text.ExampleCreate the data frameLet’s create a data frame as shown below −Names

Read More

How to split a number into digits in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 4K+ Views

To split a number into digits in R, we can use strsplit function by reading the number with as.character and then reading the output with as.numeric.For example, if we have a number stored into an object called X then we can split the number stored in X into digits by using the command as follows −as.numeric(strsplit(as.character(X),"")[[1]])Example 1To split a number into digits in R, use the snippet given below −x1

Read More

Find the percentiles for multiple columns in an R data frame.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 2K+ Views

To find the percentiles for multiple columns in R data frame, we can use apply function with quantile function and providing the quantile probabilities with probs argument.For Example, if we have a data frame called df that contains multiple columns and we want to find three percentiles 0.25, 0.70, 0.90 then we can use the command given below −apply(df[],2,quantile,probs=c(0.25,0.70,0.90))Example 1Following snippet creates a sample data frame −x1

Read More
Showing 231–240 of 1,958 articles
« Prev 1 22 23 24 25 26 196 Next »
Advertisements