دامنه تغییرات در R
Syntax
range(…, na.rm = FALSE)
...: This represents any numeric or character objects or vectors.
na.rm: This takes a Boolean value (TRUE or FALSE) indicating if the NaN (Not a Number) values should be omitted or not.
#example 1
# creating an input vector object
a <- c(1, 2, 3, 4, 10, NaN)
# calling the range() function
range(a, na.rm=TRUE)
Output
[1] 1 10
چارک ها در R
Syntax
quantile(x, probs = , na.rm = FALSE)
X = the input vector or the values
Probs = probabilities of values between 0 and 1
na.rm = removes the NA values.
#example 1
df<-c(12,3,4,56,78,18,46,78,100)
quantile(df)
Output:
0% 25% 50% 75% 100%
3 12 46 78 100
#example2
df<-c(12,3,4,56,78,18,NA,46,78,100,NA)
#removes the NA values and returns the percentiles
quantile(df,na.rm = TRUE)
#output
0% 25% 50% 75% 100%
3 12 46 78 100
#example3
df<-c(12,3,4,56,78,18,NA,46,78,100,NA)
#returns the 22 and 77th percentiles of the input values
quantile(df,na.rm = T,probs = c(0.22,0.77))
#Probs: The probs or the probabilities argument should lie between 0 and 1
#output
22% 77%
10.08 78.00
#example4
x<-c(15,20,22,25,30,34,37,40,45)
quantile(x, probs = c(0.125,0.375,0.625,0.875))
#output
12.5% 37.5% 62.5% 87.5%
20 25 34 40
Get the quantiles for the multiple groups/columns in a data set
I am going to use the ‘mtcars’ data set for this purpose and also using the ‘dplyr’ library for this.
#reads the data
data("mtcars")
#returns the top few rows of the data
head(mtcars)
#install required paclages
install.packages('dplyr')
library(dplyr)
#using tapply, we can apply the function to multiple groups
do.call("rbind",tapply(mtcars$mpg, mtcars$gear, quantile))
#output
0% 25% 50% 75% 100%
3 10.4 14.5 15.5 18.400 21.5
4 17.8 21.0 22.8 28.075 33.9
5 15.0 15.8 19.7 26.000 30.4
دوره های آموزشی ما برای کنکور ارشد و دکتری رشته های روانشناسی، مشاوره، علوم تربیتی، پرستاری, مدیریت آموزشی و علوم شناختی کاربرد دارد.