1. How to find out the first and third quartile and the Inter Quartile Range in a box plot.
I have used the diamonds dataset which is available in R. Simply type data(diamonds) to load the dataset into R.
To find the lower(first) and upper(third) quartiles, we can use the quantile function.
quantile(subset(diamonds,diamonds$color=='D')$price)
The quantile accepts only numeric values. So after you have subsetted your dataset be sure to add the column with numeric values.
To find the datatype of the column you can use the str function
str(diamonds)
- To find the IQR or Inter Quartile Range which is the difference between the Upper and Lower Quartiles we can use the IQR function
IQR(subset(diamonds,diamonds$color=='D')$price)
2. How to obtain the month from a date
I have a column where I have dates as factors. The name of the column is 'Old_Date' and the name of my data frame is ba
E.g. 11/25/2014
Steps :
1. Convert the old date to new date using the as.date() function
ba$newdate <- as.Date(ba$dates,"%m/%d/%y")
2. Use strftime to obtain the month in a numeric format. So for our example, the answer would be 11
ba$month <- strftime(ba$newdate,"%m")
I have used the diamonds dataset which is available in R. Simply type data(diamonds) to load the dataset into R.
To find the lower(first) and upper(third) quartiles, we can use the quantile function.
quantile(subset(diamonds,diamonds$color=='D')$price)
The quantile accepts only numeric values. So after you have subsetted your dataset be sure to add the column with numeric values.
To find the datatype of the column you can use the str function
str(diamonds)
- To find the IQR or Inter Quartile Range which is the difference between the Upper and Lower Quartiles we can use the IQR function
IQR(subset(diamonds,diamonds$color=='D')$price)
2. How to obtain the month from a date
I have a column where I have dates as factors. The name of the column is 'Old_Date' and the name of my data frame is ba
E.g. 11/25/2014
Steps :
1. Convert the old date to new date using the as.date() function
ba$newdate <- as.Date(ba$dates,"%m/%d/%y")
2. Use strftime to obtain the month in a numeric format. So for our example, the answer would be 11
ba$month <- strftime(ba$newdate,"%m")
No comments:
Post a Comment