Nizamuddin Siddiqui has Published 2307 Articles

Extract string vector elements up to a fixed number of characters in R.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 07:26:05

449 Views

To extract string vector elements up to a fixed number of characters in R, we can use substring function of base R.For Example, if we have a vector of strings say X that contains 100 string values and we want to find the first five character of each value then ... Read More

How to create histogram for discrete column in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 07:19:31

3K+ Views

To create histogram for discrete column in an R data frame, we can use geom_bar function of ggplot2 package and set the width to 1 also passing same column for x and y in aes.For example, if we have a data frame called df that contains a discrete column say ... Read More

How to create a column with ratio of two columns based on a condition in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 07:17:25

565 Views

To create a new column with ratio of two columns based on a condition in an R data frame, we can use division sign with ifelse function.For example, if we have a data frame called df that contains two columns say X and Y and we want to create a ... Read More

How to display X-axis tick marks as minimum and maximum only without their values using plotly in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 07:08:52

391 Views

To display X-axis tick marks as minimum and maximum only without their values using plotly, we can use layout function of plot_ly package where we can pass the values for minimum and maximum using xaxis argument and the text using ticktext argument as shown in the below example.ExampleFollowing snippet creates ... Read More

How to find the intersection of elements in a string vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 07:05:50

550 Views

If we have a string vector that contains more than one element then there might exists some common values in all the elements. If we want to find those values then intersect function can be used along strsplit function and Reduce function.Check out the below Examples to understand how it ... Read More

How to find the sum of values based on two groups if missing values are present in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 07:03:53

252 Views

To find the sum of values based on two groups if missing values are present, we can use group_by and summarise function of dplyr package.For example, if we have a data frame called df that contains a numerical column say Num and two grouping columns say Grp1 and Grp2 then, ... Read More

How to deal with error “var(x) : Calling var(x) on a factor x is defunct.” in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 06:56:50

3K+ Views

The error “Calling var(x) on a factor x is defunct” occurs when we try to apply a numerical function on factor data.For example, if we have a factor column in a data frame then applying numerical functions on that column would result in the above error. To deal with this ... Read More

How to find the trimmed mean for a column of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 06:55:54

397 Views

Trimmed mean is the mean that find the mean of values by excluding a small percentage of smallest and largest values. If we have a 5% trimmed mean that means 2.5% of smallest values and 2.5% of largest values are trimmed from the data and then the mean of the ... Read More

Roll up R data frame columns for summation by group if missing values exist in the data frame.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 06:50:37

400 Views

The summation of column values if missing values exist in the R data frame can be found with the help of summarise_each function of dplyr package where we can remove missing values by setting na.rm argument to TRUE.Since, we we will have groups in the data frame hence group_by function ... Read More

How to create a base R plot without axes but keeping the frame of the plot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 06:37:11

286 Views

To create a base R plot without axes but keeping the frame of the plot, we can set axes argument to FALSE and frame.plot argument to TRUE.For example, if we have a vector called V and we want to create a plot of V without axes but with the frame ... Read More

Advertisements