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
Programming Articles - Page 931 of 3363
962 Views
To combine values of two columns separated with hyphen in an R data frame, we can use apply function.For Example, if we have a data frame called df that contains only two columns say X and Y then we can combine the values in X and Y by using the below command given below −df$X_Y
6K+ Views
To find the class of columns of an R data frame, we can use class function along with sapply and as.data.frame function.For Example, if we have a data frame called DF then we can find the class of columns in DF by using the command as follows −data.frame(sapply(DF, class))Example 1Consider the below data frame −head(mtcars, 20) The following dataframe is created mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160.0 110 3.90 ... Read More
1K+ Views
A list in R can have large number of elements and also of different types. If we have a list that contain vectors and we want to check which list element contains a particular value then we can use which function along with sapply function.For Example, if we have a list called LIST then we can find which element of LIST contains 5 then we can use the command given below −which(sapply(LIST, FUN=function(X) 5 %in% X))Example 1Consider the List given below −List1
2K+ Views
To convert strings in R data frame to unique integers, we first need to extract the unique strings in the data frame and then read them inside data.frame function with as.numeric along with factor function.Check out the below Examples to understand how it works.Example 1Consider the below data frame −x1
3K+ Views
If we have a vector of dates that contains all days in a week then we can use that vector to create a date column by excluding weekends with the help of subsetting the vector as shown in the below Examples. After subsetting the vector, we will just need to pass the vector in data.frame function.Example 1Consider the below vector of dates −x
825 Views
The default boxplot in R has straight border line type that display end point(s) excluding outliers. To change these border lines from a boxplot, we can use staplelty argument.For Example, if we have a vector called X then we can create the boxplot of X with different border line type by using the command boxplot(X,staplelty=15). The argument can take different values. Check out the below Examples to understand how it works.ExampleConsider the below vector −x
1K+ Views
The default boxplot in R has dotted whisker lines and if we want to change it to something else, we can use the whisklty argument.For Example, if we have a vector called X then we can create the boxplot of X with different whisker line by using the command boxplot(X,whisklty=1). The argument can take different values.Check out the Examples given below to understand how it works.ExampleConsider the vector given below −x
4K+ Views
To change the outlines color of histogram bars using ggplot2, we can use col argument inside geom_histogram function of ggplot2 package.For Example, if we have a data frame called df that contains a column say X then we can create the histogram of X with different outline color of bars using the below command −ggplot(df,aes(X))+geom_histogram(bins=30,col=I("red"))ExampleFollowing snippet creates a sample data frame −x
390 Views
To find the standard deviation for every n number of observations in an R data frame, we can use rollapply function of zoo package.For Example, if we have a data frame called df that contains a column say X containing 100 values then we can create a column with standard deviation of every 10 values by using the below command −df$SD_10
98 Views
To create a number vector in R with initial values as zero by defining the maximum digits for each value, we can use sprintf function.For Example, if we want to create a number vector having values starting from 1 to 100 and we want to have 1 as 001 and so on then, we can use the below command −sprintf('%0.3d',1:100)ExampleFollowing snippet creates a sample data frame −x1