Articles on Trending Technologies

Technical articles with clear explanations and examples

How to print the exact values of all elements in a column of an R data frame?

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

To print the exact values of all elements in a column of an R data frame, we can follow the below stops −First of all, create a data frame.Then, use options function and provide the required number of digits for printing.ExampleCreate the data frameLet’s create a data frame as shown below −x

Read More

How to change the color code of corrplot in R?

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

To change the color code of corrplot, we can use colorRampPalette function inside corrplot function. We can provide different colors in colorRampPalette that we want to display in the corrplot.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 check if two vectors are exactly same in R?

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

To check if two vectors are exactly same, we can use identical function.For example, if we have two vectors say x and y then we can find whether both of them are exactly same or not by using the command given below −identical(x,y)Check out the below examples to understand the result of identical function for two vectors.Example 1To check if two vectors are exactly same, use the command given below −x1

Read More

Change the outline color for histogram bars using ggplot2 in R.

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

To change the outlines color of histogram bars using ggplot2, we can use col argument inside geom_histogram function of ggplot2 package.For Example, if we have a data frame called df that contains a column say X then we can create the histogram of X with different outline color of bars using the below command −ggplot(df,aes(X))+geom_histogram(bins=30,col=I("red"))ExampleFollowing snippet creates a sample data frame −x

Read More

How to find the ID wise frequency in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 601 Views

To find the ID wise frequency in an R data frame, we can use summarise function of dplyr package after defining the ID with group_by function, also the column for which we want to find the frequency will be placed inside group_by function.Check out the below examples to understand how it can be done.Example 1Following snippet creates a sample data frame −ID

Read More

Find the standard deviation for every n number of observations in an R data frame column.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 440 Views

To find the standard deviation for every n number of observations in an R data frame, we can use rollapply function of zoo package.For Example, if we have a data frame called df that contains a column say X containing 100 values then we can create a column with standard deviation of every 10 values by using the below command −df$SD_10

Read More

How to find the mean of all columns by group in R?

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

To find the mean of all columns by group, we can use summarise_all function along with mean function after defining the groups with group_by. For example, if we have a data frame called df that contains a grouping column say G and some numerical columns then we can find the mean of all columns by values in grouping column by using the below given command −df%>%group_by(G)%>%summarise_all("mean")Example 1Following snippet creates a sample data frame −Grp

Read More

How to find the mean of every n values in an R vector?

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

To find the mean of every n values in an R vector, we would first need to convert the vector into matrix with number of rows based for n values then we can use colMeans function.For example, if we have a vector called X that contains hundred values then we can find the mean of every ten value by using the command given below −colMeans(matrix(X,10))Example 1To find the mean of every n values in an R vector, use the command given below −x1

Read More

How to find the most frequent factor value in an R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 16K+ Views

To find the most frequent factor value in an R data frame column, we can use names function with which.max function after creating the table for the particular column. This might be required while doing factorial analysis and we want to know which factor occurs the most.Check out the below examples to understand how it can be done.Example 1Following snippet creates a sample data frame −Factor_1

Read More

How to extract the first row of each matrix stored in a list in R?

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

To extract the first row of each matrix stored in a list in R, we can use lapply function. For example, if we have a list called LIST that contains some matrices then we can find the first row of each matrix by using the command given below − lapply(LIST,'[',1,)Check out the below given example to understand how it can be done.ExampleFollowing snippet creates a list of matrices −M1

Read More
Showing 47381–47390 of 61,297 articles
Advertisements