Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1653 of 2646
2K+ Views
If you have a csv file on Github then it can be directly imported in R by using its URL but make sure that you click on Raw option on Github page where the data is stored. Many people do not click on Raw option therefore they read HTML instead of CSV and get confused. Here, I am sharing a public data set that contains the list of data sets. This data set has 12 variables. Now let’s import it −> Data str(Data) 'data.frame': 57 obs. of 12 variables: $ Dataset.Name : Factor w/ 57 levels " ", "2008 Election ... Read More
1K+ Views
If there is a category for which the frequency is significantly different from others then the X-axis labels of the bar plot using ggplot2 are automatically sorted to present the values alternatively. We might want to keep the original sequence of categories that is available in the categorical variable. Therefore, we can store the categorical variable as a factor and then create the bar plot.ExampleConsider the below data frame −> Group Frequency df df Group Frequency 1 India 12 2 USA 18 3 UK 35 4 Germany 20 > ... Read More
2K+ Views
Create a vector with dates is not an easy task but with help of seq and as.Date it becomes easy in R. With the help of these functions we can create a vector in R that contain dates between two dates. But this cannot be done in reverse order, for example, if we want to have future date as first element of the vector then it would not be possible.Example> V1 V1 [1] "2020-01-01" "2020-01-02" "2020-01-03" "2020-01-04" "2020-01-05" [6] "2020-01-06" "2020-01-07" "2020-01-08" "2020-01-09" "2020-01-10" [11] "2020-01-11" "2020-01-12" "2020-01-13" "2020-01-14" "2020-01-15" [16] "2020-01-16" "2020-01-17" "2020-01-18" "2020-01-19" "2020-01-20" [21] "2020-01-21" "2020-01-22" "2020-01-23" ... Read More
525 Views
We might want to extract row index irrespective of its type (whether numeric or string) to do some calculations if it is incorrectly set as a row index. It happens during the data collection process or incorrect processing of data. Also, since row indexes are helpful to access row we must have proper names to them instead of values that might makes confusion. For example, if a data frame has row indexes as 43, 94, etc. then it might be confusing. Therefore, we should convert row indexes to a vector or a column if required.ExampleConsider the below data frame (Here, ... Read More
345 Views
A scatterplot is used to observe the relationship between two continuous variables. If the sample size is large then the points on the plot lie on each other and does not look appealing. Also, the interpretation of such type of scatterplots is not an easy task, therefore, we can increase the transparency of points on the plot to make it more appealing. We can do this by using alpha argument in geom_point of ggplot2.ExampleConsider the below data frame −> set.seed(123) > x y df library(ggplot2) > ggplot(df, aes(x, y))+geom_point()Output> ggplot(df, aes(x, y))+geom_point(alpha=0.10)Output> ggplot(df, aes(x, y))+geom_point(alpha=0.05)OutputRead More
442 Views
If there are NA’s in our data set for multiple values of numerical variables with the grouping variable then using na.rm = FALSE needs to be performed multiple times to find the mean or any other statistic for each of the variables with the mean function. But we can do it with summarise_all function of dplyr package that will result in the mean of all numerical variables in just two lines of code.ExampleLoading dplyr package −> library(dplyr)Consider the ToothGrowth data set in base R −> str(ToothGrowth) 'data.frame': 60 obs. of 3 variables: $ len : num 4.2 11.5 7.3 5.8 ... Read More
217 Views
When we have one common column in two data frames then joining of those data frames might be used to create a bigger data frame. This will help us to analyze a combined data set with many characteristics. We can do this by using inner_join function of dplyr package.ExampleConsider the below data frames −> set.seed(111) > x1 R1 df1 df1 x1 R1 1 1 78 2 2 84 3 3 83 4 4 47 5 5 25 6 1 59 7 2 69 8 3 35 9 4 72 10 5 26 11 1 49 12 2 45 13 3 74 14 4 8 15 5 100 16 1 96 17 2 24 18 3 48 19 4 95 20 5 7 > x1 R2 df2 df2 x1 R2 1 1 21 2 2 15 3 1 1 4 2 9 5 1 63 6 2 40 7 1 25 8 2 35 9 1 71 10 2 52Loading dplyr package −> library(dplyr)Merging two data frames −> inner_join(df2,df1) Joining, by = "x1" x1 R2 R1 1 1 21 78 2 1 21 59 3 1 21 49 4 1 21 96 5 2 15 84 6 2 15 69 7 2 15 45 8 2 15 24 9 1 1 78 10 1 1 59 11 1 1 49 12 1 1 96 13 2 9 84 14 2 9 69 15 2 9 45 16 2 9 24 17 1 63 78 18 1 63 59 19 1 63 49 20 1 63 96 21 2 40 84 22 2 40 69 23 2 40 45 24 2 40 24 25 1 25 78 26 1 25 59 27 1 25 49 28 1 25 96 29 2 35 84 30 2 35 69 31 2 35 45 32 2 35 24 33 1 71 78 34 1 71 59 35 1 71 49 36 1 71 96 37 2 52 84 38 2 52 69 39 2 52 45 40 2 52 24
2K+ Views
Sometimes the data type for a variable is not correct and it is very common that a factor variable is read as a numeric variable, especially in cases where factor levels are represented by numbers. If we do not change the data type of a factor variable then the result of the analysis will be incorrect. Therefore, if a factor variable has a different data type than factor then it must be converted to factor data type. To convert multiple variables to factor type, we can create a vector that will have the name of all factor variables then using ... Read More
5K+ Views
An empty matrix can be created in the same way as we create a regular matrix in R but we will not provide any value inside the matrix function. The number of rows and columns can be different and we don’t need to use byrow or bycol argument while creating an empty matrix because it is not useful since all the values are missing. In R, one column is created by default for a matrix, therefore, to create a matrix without a column we can use ncol =0.Example> M1 M1 [, 1] [1, ] NA [2, ] NA ... Read More
511 Views
When we create a boxplot, it shows the minimum value, maximum value, first quartile, median, and the third quartile but we might want to plot means as well so that the comparison between factor levels can be made on the basis of means also. To create this type of plot, we first need to find the group-wise means then it can be used with geom_text function of ggplot2.ExampleConsider the CO2 data in base R −> head(CO2, 20) Plant Type Treatment conc uptake 1 Qn1 Quebec nonchilled 95 16.0 2 Qn1 Quebec nonchilled 175 30.4 3 Qn1 Quebec nonchilled 250 34.8 ... Read More