
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

5K+ Views
The grepl function in R search for matches to argument pattern within each element of a character vector or column of an R data frame. If we want to subset rows of an R data frame using grepl then subsetting with single-square brackets and grepl can be used by accessing the column that contains character values.Example1Consider the below data frame:Live Demo> x1 y1 z1 df1 df1Output x1 y1 z1 1 A 0.8833979 5 2 B 0.5400075 1 3 C 0.6923827 3 4 B 1.5069186 2 5 B 0.8190962 2 6 B 0.8296171 1 7 ... Read More

2K+ Views
If we have a column that represent factor then we might want to find the mean of values in other column(s) for the factor levels. This is helpful in comparing the levels of the factor. In R, we can find the mean for such type of data by using aggregate function. Check out the below examples to understand how it can be done.Example1Consider the below data frame:Live Demo> x1 y1 df1 df1Output x1 y1 1 D 5.801197 2 B 3.432060 3 B 6.154168 4 A 5.466655 5 D 5.171689 6 C 5.175170 7 B 5.353469 8 D ... Read More

2K+ Views
A string vector contains element inside double-quotes and an integer vector does not have any quotes. Sometimes integer values are stored in double-quotes hence the vector of these values is treated as a string vector in R but we need the integer values to perform mathematical operations. Therefore, we can use as.integer function to convert the string vector into an integer vector.Example1Live Demo> x1 x1Output[1] "3" "2" "1" "2" "1" "1" "1" "1" "1" "1" "3" "3" "3" "1" "2" "1" "1" "2" [19] "2" "3" "3" "3" "3" "2" "3" "3" "3" "2" "1" "2" "3" "3" "2" "1" ... Read More

265 Views
There are many ways to find the mean of a matrix elements by excluding diagonal elements, this mean is actually the mean of lower triangular matrix and the upper triangular matrix. We can simply use mean function by creating a vector of lower and upper triangular matrix as shown in the below examples.Example1Live Demo> M1 M1Output [, 1] [, 2] [, 3] [, 4] [1, ] 1 6 3 6 [2, ] 8 5 3 4 [3, ] 5 4 4 6 [4, ] 5 5 3 4 ... Read More

916 Views
The bar plot can be easily created with the help of geom_bar. But if we want to have a different border for a particular bar then we first need to create the bar plot and store it in an object. After that we need to add the original plot with the bar for which we want to have a black border. Check out the below example to understand how it can be done.ExampleConsider the below data frame:Live Demo> Group Freq df dfOutput Group Freq 1 G1 18 2 G2 27 3 G3 24Loading ggplot2 ... Read More

1K+ Views
The echelon form of a matrix is the matrix that has the following characteristics:1. The first non-zero element in each row, called the leading entry, is 1.2. Each leading entry is in a column to the right of the leading entry in the previous row.3. Rows with all zero elements, if any, are below rows having a non-zero element.In R, we can use echelon function of matlib package to find the echelon form of the matrix.ExampleLive Demo> M MOutput [, 1] [, 2] [, 3] [, 4] [, 5] [1, ] 8 11 3 10 13 [2, ] ... Read More

4K+ Views
Sometimes data is incorrectly entered into systems and that is the reason we must be careful while doing data cleaning before proceeding to analysis. A data collector or the sampled unit might enter blank to an answer if he or she does not find an appropriate option for the question. This also happens if the questionnaire is not properly designed or blank is filled by mistake. Also, if we have categorical variable then a control category might be filled with blank or we may want to have a blank category to use a new one at later stage. Whatever the ... Read More

1K+ Views
The replacement of values in a vector with the values in the same vector can be done with the help of replace function. The replace function will use the index of the value that needs to be replaced and the index of the value that needs to be placed but the output will be the value in the vector.Example1Live Demo> x1 x1Output[1] 3 0 1 0 1 1 1 1 2 1Example> replace(x1, c(10), x1[c(1)])Output[1] 3 0 1 0 1 1 1 1 2 3 Example2Live Demo> x2 x2Output[1] 5 1 4 2 3 4 2 4 5 3 6 ... Read More

639 Views
The standardization means converting a vector or column of an R data frame in a way such that the mean of the same becomes 0 and the standard deviation becomes 1, that is it should be converted to standard normal distribution. In R, it can be easily done with the help of scale function. Check out the below example to understand how it is done.ExampleConsider the below data frame:Live Demo> set.seed(3665) > x1 x2 x3 x4 x5 x6 df dfOutputx1 x2 x3 x4 x5 x6 1 1.3958185 49.39843 128.5224 3 4.183664 2.33406246 2 1.0467979 48.90103 120.5796 7 3.526731 0.02043217 3 ... Read More

623 Views
The rgb colors are referred to red green and blue. This combination helps us to create many different colors. In R, we can use rgb function to create a plot using with different colors along with the image function. If we want to have a plot with rgb colors without any axes title or axes labels then the appropriate arguments should be used inside the image function as shown in the below example.ExampleConsider the below data frame:Live Demo> set.seed(9991) > x1 x2 x3 df dfOutput x1 x2 ... Read More