R Programming Articles

Page 77 of 174

How to find the median for factor levels in R?

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

The second most used measure of central tendency median is calculated when we have ordinal data or the continuous data has outliers, also if there are factors data then we might need to find the median for levels to compare them with each other. The easiest way to do this is finding summary with aggregate function.ExampleConsider the below data frame that contains one factor column −set.seed(191) x1

Read More

How to create boxplot for multiple categories in base R?

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

To create the boxplot for multiple categories, we should create a vector for categories and construct data frame for categorical and numerical column. Once the construction of the data frame is done, we can simply use boxplot function in base R to create the boxplots by using tilde operator as shown in the below example.ExampleConsider the below data frame −Categories

Read More

How to convert negative values in an R data frame to positive values?

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

Sometimes we need to use absolute values but few values in the data set are negative, therefore, we must convert them to positive. This can be done by using abs function. For example, if we have a data frame df with many columns and each of them having some negative values then those values can be converted to positive values by just using abs(df).ExampleConsider the below data frame −set.seed(41) x1

Read More

How to create a scatterplot using five vectors in a single plot window without separating the plots in R?

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

To create more than one scatterplot in a single plot window we should create the scatterplot for first vector and then add the point of the remaining vectors by using points function and they can be displayed with different colors so that it becomes easy to differentiate among the points of the vectors.ExampleConsider the below vectors −x1

Read More

How to remove outliers from multiple boxplots created with the help of boxplot function for columns of a data frame using single line code in R?

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

A data frame can have multiple numerical columns and we can create boxplot for each of the columns just by using boxplot function with data frame name but if we want to exclude outliers then outline argument can be used. For example, if we have a data frame df with multiple numerical columns that contain outlying values then the boxplot without outliers can be created as boxplot(df,outline=FALSE).ExampleConsider the below data frame:set.seed(151) x1

Read More

How to sort a list that contains single sub-elements in decreasing order in R?

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

Just like a list can have multiple elements, the elements of the list can have multiple sub-elements and the size of those elements may vary as well hence a list with single sub-elements is also possible. If we have such type of list then we can sort that list in decreasing order by using order function but we also need to unlist those elements.ExampleConsider the below list −x1

Read More

How to find the confidence interval for the predictive value using regression model in R?

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

The confidence interval for the predictive value using regression model can be found with the help of predict function, we just need to use interval argument for confidence and the appropriate level for that. For example, if we have a model M and the data frame for the values of independent variable is named as newdata then we can use the following syntax for the confidence interval −predict(M,newdata,se.fit=TRUE,interval="confidence",level=0.95)ExampleConsider the below data frame −set.seed(1234) x1

Read More

How to remove a column from a data frame that contains same value in R?

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

If we have only one value in all of the rows of an R data frame then we might want to remove the whole column because the effect of that column will not make any sense in the data analysis objectives. Thus, instead of removing the column we can extract the columns that contains different values.Exampleset.seed(1001) x1

Read More

How to create plot in R with different shape of points?

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

In base R, the plot with different shape of points can be created by using pch argument inside the plot function. The list of pch values with shape is as written below −pch = 0 display square pch = 1 display circle pch = 2 display triangle point up pch = 3 display plus pch = 4 display cross pch = 5 display diamond pch = 6 display triangle point down pch = 7 display square cross pch = 8 display star pch = 9 display diamond plus pch = 10 display circle plus pch = 11 display triangles up ...

Read More

How to find the median of all columns in an R data frame?

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

The median is the value in a vector that divide the data into two equal parts. To find the median of all columns, we can use apply function. For example, if we have a data frame df that contains numerical columns then the median for all the columns can be calculated as apply(df,2,median).ExampleConsider the below data frame −set.seed(7) x1

Read More
Showing 761–770 of 1,740 articles
« Prev 1 75 76 77 78 79 174 Next »
Advertisements