R Programming Articles

Page 140 of 174

How to create pie chart in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 27-Oct-2021 275 Views

A pie chart is a circular representation of data which is created for either nominal data or ordinal data. The slices in the pie chart depend on the magnitude of the data values. If we want to create a pie chart in base R then pie function can be used.For Example, if we have a vector called X then the pie chart for values in X can be created by using the below command −pie(X)ExampleFollowing snippet creates a sample data frame −x

Read More

Create a sample of data frame column by excluding NAs in R

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 27-Oct-2021 306 Views

To create a random sample by excluding missing values of a data frame column, we can use sample function and the negation of is.na with the column of the data frame.For Example, if we have a data frame called df that contains a column X which has some NAs then we can create a random sample of size 100 of X values by using the following command −sample(df$X[!is.na(df$X)],100,replace=TRUE).Example 1Following is the code snippet to create dataframe −x

Read More

How to create a correlation matrix by a categorical column in data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Aug-2021 1K+ Views

To create a correlation matrix by a categorical column in data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, find the correlation matrix by splitting the object based on categorical column.Create the data.table objectLoading data.table package and creating a data.table object −library(data.table) x

Read More

What are the different color palettes we have in RColorBrewer package?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Aug-2021 290 Views

The different color palettes can be found by using display.brewer.all() function. Each of the palette has different colors. There are three types of palettes defined with names equential, diverging, and qualitative. They are defined for specific uses as written below −Sequential palettes are suited to ordered data that progress from low to high.Diverging palettes put equal emphasis on mid-range critical values and extremes at both ends of the data range.Qualitative palettes are best suited to representing nominal or categorical data.Find the color palettes in RColorBrewer packageInstalling and Loading RColorBrewer package and finding the different color palettes −install.packages("RColorBrewer") library(RColorBrewer) display.brewer.all()On executing, ...

Read More

How to randomize column values of a data.table object for all columns in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Aug-2021 323 Views

To randomize column values of a data.table object for all columns in R, we can follow the below steps −First of all, create a data.table object.Then, use sample function with lapply to randomize the columns of the data.table object.Create the data frameLet's create a data frame as shown below −library(data.table) x

Read More

How to add values in columns having same name and merge them in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Aug-2021 2K+ Views

To add values in columns having same name and merge them in R, we can follow the below steps −First of all, create a data frame.Add column values that have same name and merge them by using cbind with do.call.Create the data frameLet's create a data frame as shown below −df

Read More

How to change the color of line of a plot created for an xts object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Aug-2021 301 Views

To change the color of line of a plot created for an xts object in R, we can follow the below steps −First of all, create a data frame.Then, convert this data frame into an xts object.Create the plot for the data in xts object with default color.Then, create the plot for the data in xts object with different colorCreate the data frameLet's create a data frame as shown below −Dates

Read More

How to add a column to data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 13-Aug-2021 6K+ Views

To add a column to data.table object, we can follow the below steps −First of all, create a data.table object.Add a column to the object using := functionCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) x

Read More

How to find the number of rows in a data.table where two or more column values meet a criteria in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 13-Aug-2021 511 Views

To find the number of rows in a data.table where two or more column values meet a criteria, we can follow the below steps −First of all, create a data.table object.Find the number of rows meeting a criteria.Create data.table objectLet’s create a data.table object as shown below −x

Read More

How to divide the row values by row mean in data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 13-Aug-2021 179 Views

To divide the row values by row mean in R’s data.table object, we can follow the below steps −First of all, create a data.table object.Then, use apply function to divide the data.table object row values by row mean.Create the data framelibrary(data.table) x

Read More
Showing 1391–1400 of 1,740 articles
« Prev 1 138 139 140 141 142 174 Next »
Advertisements