
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
Found 33676 Articles for Programming

654 Views
In data analysis, finding some NA values in a data frame is very common but all the NA values do not create problems if the column that contain NA values is not useful for the analysis. We can replace all NA values to 0 or to any other for the columns that are useful.ExampleConsider the below data frame −> set.seed(99) > x1 x2 x3 x4 x5 df df x1 x2 x3 x4 x5 1 NA NA 25 NA 2 5 2 24 f 2 3 NA ... Read More

543 Views
The number of words in a sentence could be used for text analysis, therefore, we are required to count them. This can be for a single sentence or for multiple sentences. We can find the number of words in a sentence or in multiple sentences using strsplit with sapply.ExampleConsider the below sentences read as vectors −> x1 x1 [1] "Data Science is actually the Statistical analysis" > sapply(strsplit(x1, " "), length) [1] 7 > x2 x2 [1] "China faced trouble even after controlling COVID-19" > sapply(strsplit(x2, " "), length) [1] 7 > x3 x3 [1] "Corona virus has changed everything ... Read More

1K+ Views
While creating plots using ggplot2, the plot area is of square shape but we can change our plot area by setting plot.margin in theme function. This is helpful when we want to decrease the plot area and also when the data points are less.ExampleConsider the below data frame −> set.seed(1) > x y df library(ggplot2)Creating the scatterplot without changing the plot area margins −> ggplot(df,aes(x,y))+ + geom_point()> ggplot(df,aes(x,y))+ + geom_point()+ + theme(plot.margin = unit(c(1,1,1,1), "cm"))> ggplot(df,aes(x,y))+ + geom_point()+ + theme(plot.margin = unit(c(2,2,2,2), "cm"))

1K+ Views
Generally, a list in R contains a large number of elements and each element can be of different type which is a great thing about lists. Since we can store type of data as a list element therefore storage and selection to different type of data becomes easier. And we can also select single or multiple elements of the list at a time. This can be done with the help of single square brackets.ExampleConsider the below list −> list_data list_data [[1]] [1] "India" [[2]] [1] "China" [[3]] [1] 21 32 11 [[4]] [1] "a" "b" "c" "d" "e" [[5]] ... Read More

2K+ Views
A matrix can have multiple rows and columns like a data frame. As in data frames, we sometimes require to take subsets, the same might be required with matrices. But subsetting matrices data is quite simple as compared to subsetting a data frame.ExampleConsider the below matrix −> M M [, 1] [, 2] [, 3] [, 4] [, 5] [1, ] 1 6 11 16 21 [2, ] 2 7 12 17 22 [3, ] 3 8 13 18 23 [4, ] 4 9 14 19 24 [5, ] 5 10 15 20 25Subsetting columns of matrix M −> M[, ... Read More

572 Views
When there is a common factor with different levels, the joining of data frames is possible but the result will present all the levels with dplyr. We can make use of left_join function to join the two data frames but the size of the first data frame must be greater than the second data frame if they are not same.ExampleConsider the below data frames −> Class df1 df1 Class 1 Statistics 2 Maths 3 Chemistry 4 Physics 5 Economics 6 Political Science 7 Geography > Subject Age df2 df2 Subject Age 1 Maths 18 2 Chemistry 21 3 Physics 22 ... Read More

624 Views
Selection of top or bottom elements can be done with the help of head and tail function in R. It is required when we want to understand the data in a vector or perform some calculation for partial data.ExampleConsider the below vectors, we will use head and tail to select top and bottom elements in these vectors by using positive and negative signs. These will have a different way to select the elements.> x x [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" ... Read More

4K+ Views
Sometimes the lists are contained in another list but we want to access the nested list’s elements. Since these elements are part of a list then cannot be directly accessed, first we need to access the broader list and then the list that contains the element to reach the actual element.ExampleConsider the lists x1, x2, x3, x4, and x4 and the Total_List that contains these lists −> x1 x2 x3 x4 x5 Total_Lists Total_Lists [[1]] [[1]][[1]] [1] 1 2 3 4 5 [[1]][[2]] [1] 6 7 8 9 10 [[1]][[3]] [1] 11 12 13 14 15 [[2]] [[2]][[1]] [1] "a" ... Read More

3K+ Views
When we deal with large data then the problem of printing the data or output of the analysis arises. Due to this problem, it becomes difficult to have a look at our complete but it can be avoided. Before importing any large data or performing any calculation that may result in big output, we can change the limit of the printing by using max.print option.Example> set.seed(1) > sample(1:1000, 555555, replace=TRUE)Output[99681] 223 62 961 304 5 262 519 357 415 167 855 523 268 486 [99695] 370 916 703 179 813 833 177 154 72 789 924 918 486 647 [99709] ... Read More

1K+ Views
Dealing with big data frames is not an easy task therefore we might want to split that into some smaller data frames. These smaller data frames can be extracted from the big one based on some criteria such as for levels of a factor variable or with some other conditions. This can be done by using split function.ExampleConsider the below data frame −> set.seed(1) > Grades Age Category df head(df, 20) Grades Age Category 1 A 25 6 2 B 4 ... Read More