Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Nizamuddin Siddiqui
Page 26 of 196
How to add suffix to column names in R?
To add suffix to column names in R, we can use paste function. For example, if we have a data frame called df that contains three columns say x, y, and z and we want to add a suffix to these columns say underscore1 (_1) then it can be done by using the commandcolnames(df) x y z df1 df1Output x y z 1 6 3 2 2 9 7 5 3 5 7 6 4 5 9 6 5 2 5 9 6 4 5 4 7 2 0 7 8 2 5 8 9 4 5 8 10 6 ...
Read MoreHow to find the length of columns for missing values in R?
The length of columns for missing values means the number of missing values in the data frame. This can be easily done with the help of colSums function where we will find the total number of NA values with is.na. For example, if we have a data frame called df that contains some missing values then the length of columns for missing values can be found by using the command colSums(is.na(df)).Example1Consider the below data frame −> x1 x2 x3 x4 df1 df1Output x1 x2 x3 x4 1 NA NA 2 2 2 NA NA NA 2 3 1 NA ...
Read MoreHow to match a column in a data frame with a column in another data frame in R?
To match a column in a data frame with a column in another data frame, we can use match function. For example, if we have two data frames called df1 and df2 each having one similar column and the second having an extra column then the matching can be done for similar columns and a new column in the first data frame can be created based on that match and the second column the second data frame. Check out the below examples to understand how it works.Example1> df1 df1Output x1 1 2 2 2 3 1 4 ...
Read MoreHow to combine a data frame and a named vector if name matches with a column in R?
If we have a data frame that contains a character column and a named vector which has the same names as in the character column of the data frame then we can combine this data frame and the vector by using match function be appropriately defining the names and the character column. Check out the below example to understand how it can be done.ExampleConsider the below data frame df1 and the vector v1 −df1
Read MoreHow to standardize only numerical columns in an R data frame if categorical columns also exist?
The standardization of a numerical column can be easily done with the help of scale function but if we want to standardize multiple columns of a data frame if categorical columns also exist then mutate_if function of dplyr package will be used. For example, if we have a data frame df then it can be done as df%>%mutate_if(is.numeric, scale)Example1Consider the below data frame −> x1 x2 df1 df1Output x1 x2 1 c 4 2 c 1 3 a 4 4 a 1 5 b 0 6 c 4 7 c 2 8 ...
Read MoreHow to find the number of groupwise missing values in an R data frame?
In data science, we often face the problem of missing values and we need to define a way to replace them with an appropriate value or we can complete remove them. If we want to replace the missing then we also need to know how many missing values are there. Therefore, if we have a data frame with grouping column then finding the number of groupwise missing values can be done with aggregate function as shown in the below examples.Example1Consider the below data frame −> Group x df1 df1Output Group x 1 A 2 2 A ...
Read MoreHow to change the tick size using ggplot2 in R?
To change the tick size using ggplot2, we can use theme function with argument axis.ticks.length. For example, if we have a data frame called df that contains two columns say x and y then the scatterplot between x and y with larger size of tick marks can be created by using the below command −ggplot(df,aes(x,y))+geom_point()+theme(axis.ticks.length=unit(0.8,"inch"))ExampleConsider the below data frame −x
Read MoreHow to convert the row values in a matrix to row percentage in R?
To convert the row values in a matrix to row percentage, we can find the row sums and divide each row value by this sum. For example, if we have a matrix called M then we can convert the row values in M to row percentage by using the commandround((M/rowSums(M))*100,2)ExampleConsider the below matrix −M1
Read MoreHow to create horizontal lines for each bar in a bar plot of base R?
To create horizontal lines for each bar in a bar plot of base R, we can use abline function and pass the same values as in the original barplot with h argument that represents horizontal with different color to make the plot a little better in terms of visualization.Examplex
Read MoreHow to calculate the z score for grouped data in R?
To calculate the z score for grouped data, we can use ave function and scale function. For example, if we have a data frame called df that contains a grouping coloumn say GROUP and a numerical column say Response then we can use the below command to calculate the z score for this data −ave(df$Response,df$GROUP,FUN=scale)ExampleConsider the below data frame −grp
Read More