Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 116 of 196

Find the frequency of successive occurrences less than equal to a threshold in an R data frame column?

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

To find the frequency of successive occurrences less than a threshold value in an R data frame column, we can use rle function along with sum function.Check out the below given examples to understand how it can be done.Example 1Following snippet creates a sample data frame −x

Read More

How to find numbers that are divisible by a certain number for a range of values in R?

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

In R, the divisibility of a number by a certain number can be found by using the modulus operator %%. If we want to check the divisibility of a set of numbers by a certain number then for loop will be used.Check out the below given examples to understand how it can be done.Example 1To check which numbers between 1 and 100 are divisible by 10, use the following code −for(x in 1:100){    + if(x%%10==0){          + print(x)    + } + }If you execute the above given code, it generates the following output −[1]  10 ...

Read More

How to create a scatterplot with white background and no gridlines using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 414 Views

Practically, the scatterplots are well visualized on white background just like on white paper. If we want to create a scatterplot with white background and without gridlines using ggplot2 then we can apply classic theme to the plot.Check out the below given example to understand how it can be done.ExampleFollowing snippet creates a sample data frame −x

Read More

How to find the number of unique values in comma separated strings stored in an R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 575 Views

If we have comma separated values that contains duplicate and unique values then we might want to find the number of unique values within each comma separated value. To find the unique values in comma separated strings stored in an R data frame column, we can use stri_extract_all_regex function of stringi package along with sapply function.Check out the below examples to understand how it can be done.Example 1Following snippet creates a sample data frame −x

Read More

How to combine columns by excluding missing values in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 410 Views

If we have a data set that contains missing values at alternate places for each column then we might want to combine the columns by excluding those missing values, this will reduce the data set and the analysis is likely to become easier.For this purpose, we can use na.exclude function along with apply function as shown in the below given examples.Example 1Following snippet creates a sample data frame −x1

Read More

How to create a matrix in R by filling the data with predefined values in loop?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 823 Views

If we know the total number of rows we want in our matrix and the number of columns then we can use matrix function to create a matrix by filling the data with predefined values. These values must be equal to the multiplication of number of rows and columns.Check out the below given examples to understand how it works.Example 1Following snippet creates a matrix in R by filling the data with predefined values in loop −n=20 k=2 data=rpois(n*k, 5) M1=matrix(data, nrow=n, ncol=k) M1If you execute the above given snippet, it generates the following output −     [, 1] [, 2] ...

Read More

How to convert character column of a matrix into numeric in R?

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

If we have a matrix that contains character columns and we want to convert a single column to numeric then we first need to convert the matrix into a data frame using as.data.frame function after that as.numeric function can be used to change the particular column to numeric type as shown in the below examples.Example 1Following snippet creates a matrix −M1

Read More

How to find the average of a particular column in R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 14K+ Views

To find the average of a particular column in R data frame, we can take the help of delta ($) operator.For example, if we have a data frame called df that contains a column x then we can find the average of column x by using the command given below −mean(df$x)Example 1Following snippet creates a sample data frame −x1

Read More

How to find the mean of all matrices stored in an R list?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 470 Views

To find the mean of all matrices stored in an R list, we can use sapply function along with mean function. For example, if we have a list called LIST that contains some matrices then the mean of each matrix can be found by using the command given below −sapply(LIST,mean)Check out the below given example to understand how it works.ExampleFollowing snippet creates a list of matrices −M1

Read More

How to update single value in an R data frame?

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

To update single value in an R data frame, we can use row and column indices with single square brackets.For example, if we have a data frame called df that contains two columns and ten rows and if we want to change the fifth value in second column to 10 then we can use the command given below −df[5,2]

Read More
Showing 1151–1160 of 1,958 articles
« Prev 1 114 115 116 117 118 196 Next »
Advertisements