Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 137 of 196

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 167 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 261 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

How to round each value to two decimal places in columns if some columns are categorical in R data frame?

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

To round each value to two decimal places in columns if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to round each value to two decimal places in columns if some columns are categorical.ExampleCreate the data frameLet’s create a data frame as shown below −Level

Read More

How to check if a set is a subset of another set in R?

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

To check if a set is a subset of another set, we can use all function with %in% operator. For example, if we have two vectors say x and y and we want to check whether x is a subset of y then we can use the command given below −all(x %in% y)Check out the below given examples to understand how it works.Example 1To check if a set is a subset of another set in R, use the snippet given below −set_x1

Read More

How to find the length of sequence vector in R?

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

A sequence vector is created by using the sequence of numbers such as 1 to 15, 21 to 51, 101 to 150, -5 to 10. The length of this type of vectors can be found only by using the length function.For example, if we have a sequence vector say X then the length of X can be found by using the command given below −length(X)Example 1To find the length of sequence vector in R, use the code given below −x1

Read More

How to find the log of each value in columns if some columns are categorical in R data frame?

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

To find the log of each value if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to find the log if some columns are categorical.ExampleCreate the data frameLet’s create a data frame as shown below −Level

Read More

How to find the cross product of two vectors in R by adding the elements?

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

To find the cross product of two vectors in R by adding the elements, we can calculate outer product by using %o% operator.For example, if we have two vectors say x and y then cross product of these two vectors by adding the elements can be found by using the command given below −x%o%yCheck out the below examples to understand how it works.Example 1To find the cross product of two vectors in R by adding the elements, use the code given below −x1

Read More
Showing 1361–1370 of 1,958 articles
« Prev 1 135 136 137 138 139 196 Next »
Advertisements