R Programming Articles

Page 141 of 174

How to find the proportion of categories based on another categorical column in R's data.table object?

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

To find the proportion of categories based on another categorical column in R's data.table object, we can follow the below steps −First of all, create a data.table object.Finding the proportion based on categorical column.Create a data.table objectLoading data.table package and creating a data.table object with two categorical columns −library(data.table) Category1

Read More

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

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

To divide the row values by row sum 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 sum.Create the data.table objectLet’s create a data.table object as shown below −library(data.table) x

Read More

How to remove only first row from a data.table object in R?

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

To remove only first row from a data.table object we can follow the below steps −First of all, creating the data.table object.Subsetting the data frame with single square brackets by negation of 1Example1Create the data frameLet's create a data frame as shown below −library(data.table) x1

Read More

How to create a bar chart for single vector using ggplot2 in R?

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

To create a bar chart for single vector using ggplot2 in R, we can follow the below steps −First of all, create a vector and melt it using melt function of reshape2 package and save the melted data.Then, create the bar chart with melted data using ggplot2.Create the vector and melt itCreating the vector and using melt function of reshape2 to melt the data in vector −x

Read More

How to divide data.table object rows by row median in R?

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

To divide the row values by row median 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 median.Create the data.table objectLet's create a data frame as shown below −> library(data.table) > x y z DT DTOn executing, the above script generates the below output(this output will vary on your system due to randomization) −    x y  z 1:  5 3  2 2:  1 3  7 3:  6 0 13 4:  6 2 10 5:  8 1  9 6:  9 ...

Read More

How to check the data frame structure without using str function in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Aug-2021 262 Views

To check the data frame structure without using str function in R, we can follow the below steps −First of all, load the data or create new data or use an in-built data set.Then, use glimpse function of tibble package.Example 1Use in-built data setConsider the mtcars data set, load the tibble package and use glimpse function to look at the structure of mtcars data −library(tibble) glimpse(mtcars)OutputRows: 32 Columns: 11 $ mpg   21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17.8, ~ $ cyl   6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, ...

Read More

How to find the number of unique values for each column in data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Mar-2021 860 Views

To find the number of unique values for each column in data.table object, we can use uniqueN function along with lapply. For example, if we have a data.table object called DT that contains five columns each containing some duplicate values then the number of unique values in each of these columns can be found by using DT[,lapply(.SD,uniqueN)].ExampleConsider the below data.table object −x1

Read More

Write a C program to work on statements using functions and loops

Bhanu Priya
Bhanu Priya
Updated on 10-Mar-2021 223 Views

ProblemHow to print the long lines into two or more short lines based on specified length in the program using C Language?SolutionLet’s write a code to read a long line and print into two or more short lines according to the mentioned size in the program.The built in functions that we take in this program readline() function, is used to store text in array and returns the size of line.The logic we use to read a short sentence is explained below −while((charcter=readtext())>0){    if(charcter>length){       count=0;       a=0;       while(alength){          count=0;          a=0;          while(a

Read More

How to multiply large numbers with all digits in the output in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 06-Mar-2021 324 Views

To multiply large numbers with all digits in the output, we can use mul.bigz function of gmp package. For example, if we have two vectors say x and y each containing numbers of large size then the multiplication of these numbers that will return all the digits of the multiplication can be done by using the command mul.bigz(x,y).Example1Loading gmp package and multiplying vectors containing large number values −library(gmp) x1

Read More

How to show values in boxplot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 06-Mar-2021 5K+ Views

The main values in a boxplot are minimum, first quartile, median, third quartile, and the maximum, and this group of values is also called five-number summary. Therefore, if we want to show values in boxplot then we can use text function and provide the five-number summary and labels with fivenum function as shown in the below examples.Example1x

Read More
Showing 1401–1410 of 1,740 articles
« Prev 1 139 140 141 142 143 174 Next »
Advertisements