
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 26504 Articles for Server Side Programming

670 Views
To find the last non-missing value in each column of a data.table object, we can use lapply function along with tail function for NA values.For example, if we have a data.table object called DT then we can find the last non-missing value in each column of DT by using the below given command −DT[,lapply(.SD,function(x) tail(x[!is.na(x)],1))]Example 1Following snippet creates a data.table object −library(data.table) x1

648 Views
To find the combination of columns for correlation coefficient greater than a certain value, we would first need to create the correlation matrix and then melt the correlation with the help if melt function of reshape2 package. After that subset of the output will be taken based on the value of the correlation coefficient.Check out the below examples to understand how it works.Example 1Following snippet creates a sample data frame −x1

832 Views
Sometimes numerical values are being read as strings and hence creating a matrix using that vector is not straight forward.For the conversion of text vector into a matrix, we need to use scan function and specify the appropriate number of rows or columns as shown in the below given examples.Example 1Consider the below given vector x1 −x1

2K+ Views
If we want to create side by side barplot for two vectors or two columns of same or different data frames then we first need to combine those vectors or columns with the help of cbind function as shown below. After that barplot function will be applied to the combined data and beside argument will be set to TRUE.Check out the below given example to understand how it works.ExampleTo create side by side barplot in base R, use the code given below −x

2K+ Views
To change the color of bars in base R barplot, we can use col argument inside the barplot function.For example, if we have a vector called V for which we want to create the barplot then we can use the command given below to get the bars in blue color − barplot(V,col="blue")Check out the below example to understand how it can be done.ExampleTo change the color of bars in base R barplot, use the code given below −x

356 Views
To create an alternately increasing sequence, we can take help of logical constants in the R language that is TRUE and FALSE. While creating a vector, the first value will be set to FALSE and the second value will be set to TRUE, therefore, the resulting vector will always have an alternately increasing sequence.Check out the below given examples to understand how it works.Example 1To create an alternately increasing sequence in R, use the code given below −x1

795 Views
To find the n number of quartiles for every row in an R data frame, we can use apply function along with quantile function.For example, if we have a data frame called df that contains hundred rows and we want to find two quartiles say first and third for each row then we can use the below mentioned command −apply(df,1,quantile,c(0.25,0.75))Example 1Following snippet creates a sample data frame −x1

656 Views
When we use apply function on numerical as well as character column then the output of the function returns NA for all hence to deal with this problem, we can use lapply function. The lapply function will take each column into account independently, therefore, the arithmetic operations will be performed individually.Check out the below given examples to understand how it works.Example 1Following snippet creates a sample data frame −x1

253 Views
If we have a data frame that contains some lower case and some upper-case string values then we might want to subset the data frame based on lower case or upper-case letters.For this purpose, we can make use of apply and sapply function as shown in the below examples.Example 1Following snippet creates a sample data frame −x1

2K+ Views
To check for equality of three columns by row, we can use logical comparison of equality with double equal sign (==) and & operator.For example, if we have a data frame called df that contains three columns say C1, C2, and C3 and we want to check for equality of these three columns then we can use below given command −df$All_equal