Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 132 of 196

How to create a group column in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 05-Nov-2021 1K+ Views

Suppose we have a data frame called df that contains two columns say X and Y then we can create a group column based on X and Y by converting df into a data.table object and creating list of values in X and Y with list function.Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −x1

Read More

How to multiply two matrices in R if they contain missing values?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 05-Nov-2021 894 Views

If we want to multiply two matrices if they contain missing values then we first need to convert the missing values to zeros and then the multiplication can be easily done. If we do not do so then the Output of the multiplication will have NAs at all positions.Check out the Examples given below to understand the correct of multiplication if NAs are present in the matrices.Example 1Following snippet creates a sample matrix −M1

Read More

How to hide outliers in base R boxplot?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 05-Nov-2021 397 Views

To hide outliers in base R boxplot, we can use range argument inside boxplot function but we will have to play with range argument. The range argument can take many values therefore, we would need to find the correct one that removes all the outliers. To understand how it works check out the Example given below −ExampleTo hide outliners in base R boxplot, use the following snippet −x

Read More

How to remove line numbers from data.table object in R?

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

To remove line numbers from data.table object in R, we can set row.names to FALSE and print the data.table object.For Example, if we have a data.table object called DT then we can remove line numbers from DT by using the command given below −print(DT,row.names=FALSE)Example 1To load data.table object and create an object use the following snippet to create a data frame −library(data.table) x1

Read More

Find the value in an R data frame column that exist n times.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 05-Nov-2021 222 Views

To find the value in an R data frame column that exist n times, we first need to tabulate the column with factor then extracting the levels of the column after that reading them with as.numeric.Check out the Examples given below to understand how it can be done.Example 1Following snippet creates a sample data frame −x

Read More

How to round matrix values in R?

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

To round matrix values, we can use round function.For Example, if we have a matrix called M and we want to round the value in M to 2 decimal places by using the below command −M

Read More

How to display numbers with decimal in R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 05-Nov-2021 7K+ Views

To display numbers with decimal in R data frame column, we can use format function with round function and nsmall argument.For Example, if we have a data frame called df that contains an integer column say X then we can display numbers in X with 2 decimal places by using the below command −df$X

Read More

Change the decimal point of every value in an R data frame column.

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

To change the decimal point of every value in an R data frame column, we can use round function.For Example, if we have a data frame called df that contains a column say X and we want to have each value with 3 decimal places then we can use the below command −df$X

Read More

Why Output of mean of normal random variable created using rnorm equals to 10 is not 10 in manual calculation with R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 05-Nov-2021 118 Views

When we find the mean of normal random variable which is created with rnorm(“sample_size”, 10) is not 10 because rnorm will create a random variable hence mean will be changed but as we increase the sample size the mean will become closer to 10.Check out the Examples given below to understand the variation in the Outputs as the sample size increases.ExampleThe variation in the Outputs of mean of normal random variable created by using rnorm as the sample size increases is explained below −mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(1000, mean=10)) mean(rnorm(1000, ...

Read More

Find the missing numbers in a sequence in R data frame column.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 1K+ Views

To find the missing numbers in a sequence in R data frame column, we can use setdiff function.For Example, if we have a data frame called df that contains a column say X and we want to check which values between 1 to 20 are missing in this column then we can use the below command −setdiff(1:20,df$X)Example 1Following snippet creates a sample data frame −x

Read More
Showing 1311–1320 of 1,958 articles
« Prev 1 130 131 132 133 134 196 Next »
Advertisements