R Programming Articles

Page 78 of 174

How to find the frequency of NA values per row in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 555 Views

Since column represent variables, we often find missing values in the columns of a data frame but we may want to find missing values(NA) for cases as well so that we can replace them based on case characteristic instead of the distribution of the variable. In R, we can use rowSums with apply function.ExampleConsider the below data frame −set.seed(8) x1

Read More

How to find the size of the plotting window in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

The plotting window size can be found by using dev.size function and we can pass in for inches and cm for centimeters. For example, if we create a plot then we can use dev.size("in") to find the plot size in inches and dev.size("cm") to find the size in centimeters.ExampleConsider the below vectors and create a point chart between those vectors −x

Read More

How to create histogram of all columns in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 15K+ Views

To create histogram of all columns in an R data frame, we can use hist.data.frame function of Hmisc package. For example, if we have a data frame df that contains five columns then the histogram for all the columns can be created by using a single line code as hist.data.frame(df).ExampleConsider the below data frame −set.seed(9) x1

Read More

How to create a plot with cross sign in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 424 Views

In base R, the plot with different shape of points can be created by using pch argument inside the plot function but if we want to use any sign that is not designed for pch argument by default then we should pass that particular sign. For example, if we want to use cross sign then we can use letter x with pch as pch = "x".ExampleConsider the below vector and create the plot by displaying cross sign using letter x −x

Read More

How to find the frequency of repeated and unique values in a vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 407 Views

If we unique values in a vector in R and they are repeated then we can find the frequency of those unique values, this will help us to understand the distribution of the values in the vector. On the basis of that distribution analysis, we can proceed with the further analysis that could be used. This can be done with the help of rle function.Examplex1

Read More

How to convert columns of an R data frame into rows?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 25K+ Views

If the row values are incorrectly recorded into columns then we might want to convert the columns into rows. Thus, to convert columns of an R data frame into rows we can use transpose function t. For example, if we have a data frame df with five columns and five rows then we can convert the columns of the df into rows by using as.data.frame(t(df)).Exampleset.seed(4) x1

Read More

How to create regression model line in a scatterplot created by using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 431 Views

To add a regression model line in a scatterplot created by using ggplot2, we need to use geom_smooth function to define the line for linear model. For example, if we have a data frame df that contains independent variable x and the dependent variable y then the regression line can be created by using the code −ggplot(df,aes(x,y))+geom_point()+geom_smooth(method="lm")ExampleConsider the below data frame −set.seed(133) x

Read More

How to create histogram with relative frequency in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

The relative frequency histogram can be created for the column of an R data frame or a vector that contains discrete data. For this purpose, we can use PlotRelativeFrequency function of HistogramTools package along with hist function to generate histogram. For example, if we have a vector x for which we want to create a histogram with relative frequencies then it can be done as PlotRelativeFrequency(hist(x)).ExampleConsider the below vector −x

Read More

How to find the cumulative sum for factor levels in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 696 Views

Cumulative sums are mostly used in descriptive analysis of data but sometimes we might want to calculate them in understanding the time series analysis for moving sums but it is very rare. If we have a factor column in an R data frame then it would not make sense to find the cumulative sum for all factor levels together, we must find the cumulative sums for each level. This can be easily done by using ave function.ExampleConsider the below data frame −set.seed(15) x1

Read More

How to create a point chart with empty points using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

The point chart can be created by using geom_point function and if we want to create a point chart for single vector then we should pass the vector in both the places inside aes function. Also, by default the points are complete black circles and if we want to change the points to empty points then shape argument can be used.ExampleConsider the below data frame −set.seed(171) x

Read More
Showing 771–780 of 1,740 articles
« Prev 1 76 77 78 79 80 174 Next »
Advertisements