Programming Articles - Page 1435 of 3363

How to remove rows from an R data frame that contains at least one NaN?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:37:52

472 Views

The NA values and NaN values are very different in nature, therefore, removal of rows containing NA values is different from removal of rows containing NaN values. For example, if we have a data frame that has NaN values the rows will be removed by using the is.finite function as shown in the below examples.Consider the below data frame −Example Live Demox1

How to increase the thickness of histogram lines in base R?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:32:14

2K+ Views

To increase the thickness of histogram lines in base R, we would need to use par function by defining the thickness size of the line. If we want to do so then line thickness must be defined first before creating the histogram. An example of line size could be line

How to find the row mean for columns in an R data frame by ignoring missing values?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:30:25

6K+ Views

To find the row mean for columns by ignoring missing values, we would need to use rowMeans function with na.rm. For example, if we have a data frame called df that contains five columns and some of the values are missing then the row means will be calculated by using the command: rowMeans(df,na.rm=TRUE).Consider the below data frame −Example Live Demox1

How to deal with error “Error in shapiro.test(…) : sample size must be between 3 and 5000” in R?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:22:48

4K+ Views

The shapiro.test has a restriction in R that it can be applied only up to a sample of size 5000 and the least sample size must be 3. Therefore, we have an alternative hypothesis test called Anderson Darling normality test. To perform this test, we need load nortest package and use the ad.test function as shown in the below examples.Consider the below data frame −Example Live Demox

How to display positive sign for X-axis labels in R using ggplot2?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:20:04

617 Views

By default, the positive signs are not displayed in any plot in R. It is well known that if there is no sign seen with any value then it is considered positive, therefore, we do not need the sign but to distinguish between 0 and positive values it could be done. To display positive sign for X-axis labels, we can use scale_x_continuous function.Consider the below data frame −Example Live Demox

How to change the size of plots arranged using grid.arrange in R?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:15:24

10K+ Views

To change the size of plots arranged using grid.arrange, we can use heights argument. The heights argument will have a vector equal to the number of plots that we want to arrange inside grid.arrange. The size of the plots will vary depending on the values in this vector.Consider the below data frame −Example Live Demox

How to create a cumulative sum plot in base R?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:11:00

3K+ Views

To create a cumulative sum plot in base R, we can simply use plot function. For cumulative sums inside the plot, the cumsum function needs to be used for the variable that has to be summed up with cumulation. For example, if we have two vectors say x and y then the plot with cumulative sum plot can be created as plot(x,cumsum(y)).Examplex1

How to create a plot in base R with tick marks of larger size?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 05:08:48

2K+ Views

To create a plot in base R with tick marks of larger size, we can make use of axis function tck argument. The tck argument value will decide the size of the tick mark but since the ticks lie below the plot area hence the value will have a negative associated with it. Therefore, it will be like -0.05. Check out the below examples to understand how it works.Exampleplot(1:10,axes=FALSE,frame=TRUE) axis(1,1:10,tck=-0.02) axis(2,1:10,tck=-0.02)OutputExampleplot(1:10,axes=FALSE,frame=TRUE) axis(1,1:10,tck=-0.05) axis(2,1:10,tck=-0.05)Output

How to find mode for an R data frame column?

Nizamuddin Siddiqui
Updated on 06-Feb-2021 12:02:06

3K+ Views

To find the model for an R data frame column, we can create a function and use it for the calculation. The function for mode is created as written below −mode

How to change the linetype for geom_vline in R?

Nizamuddin Siddiqui
Updated on 06-Feb-2021 11:47:16

8K+ Views

To change the linetype for geom_vline, we can use linetype argument in geom_vline function of ggplot2 package. There are mainly six linetypes that can be used and these values are 0=blank, 1=solid (default), 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash.Consider the below data frame −x

Advertisements