Found 2038 Articles for R Programming

How to find the number of zeros in each row of an R data frame?

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:52:06

996 Views

To find the number of zeros in each row of an R data frame, we can follow the below steps −First of all, create a data frame.Then, use rowSums function to find the number of zeros in each row of the data frame.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to find the number of columns where all row values are equal in R matrix?

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:49:23

263 Views

To find the number of columns where all row values are equal in R matrix, we can follow the below steps −First of all, create a matrix.Then, use sum function along with length and apply function to find the number of columns where all row values are equal.Example 1Create the matrixLet’s create a matrix as shown below −M1

Check which column names contain a specific string in R data frame.

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:57:31

4K+ Views

If we have a data frame that contains columns having names with some commong strings then we might want to find those column names. For this purpose, we can use grepl function for subsetting along with colnames function.Check out the Examples given below to understand how it can be done.Example 1Following snippet creates a sample data frame −Students_Score

How to create pivot table with sum for data stored in R data frame?

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:46:20

588 Views

To create pivot table with sum for data stored in R data frame, we can follow the below steps −First of all, create a data frame with two categorical and one numerical column.Then, use dcast function from reshape2 package to create pivot table for the data stored in data frame.ExampleCreate the data frameLet’s create a data frame as shown below −Group

Change the starting point of bars in bar plot for a ggplot2 graph in R.

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:45:15

2K+ Views

To change the starting point of bars in bar plot for a ggplot2 graph in R, we can use coord_cartesian function of ggplot2 package with ylim argument where we can change the starting and ending point for the bar plot values.Check out the Example given below to understand how it can be done.ExampleFollowing snippet creates a sample data frame −x

How to find the log10 of each value in columns if some columns are categorical in R data frame?

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:43:41

105 Views

To find the log10 of each value if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to find the log10 if some columns are categorical.ExampleCreate the data frameLet’s create a data frame as shown below −Level

How to separate two values in single column in R data frame?

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:40:30

1K+ Views

To separate two values in single column in R data frame, we can follow the below steps −First of all, create a data frame.Then, use separate function from tidyr package to separate the values in single column.ExampleCreate the data frameLet’s create a data frame as shown below −df

How to increase the length of Y-axis values for ggplot2 graph in R?

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:41:28

5K+ Views

To increase the length of Y-axis for ggplot2 graph in R, we can use scale_y_continuous function with limits argument.For Example, if we have a data frame called df that contains two columns say X and Y and we want to have the length of Y-axis starting from 1 to 10 by using the below mentioned command −ggplot(df,aes(X,Y))+geom_point()+scale_y_continuous(limits=c(1,10))ExampleFollowing snippet creates a sample data frame −x

How to standardize columns if some columns are categorical in R data frame?

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:37:31

129 Views

To standardize columns if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to standardize columns if some columns are categorical.ExampleCreate the data frameLet’s create a data frame as shown below −Level

How to convert first letter into capital in single column R data frame using a function?

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:34:13

1K+ Views

To convert first letter into capital in single column data frame in R, we can follow the below steps −First of all, create a data frame with string column.Then, use capitalize function from R.utils package to convert first letter into capital in single column.ExampleCreate the data frameLet’s create a data frame as shown below −Names

Advertisements