|R| Experts – Telegram
|R| Experts
1.05K subscribers
376 photos
35 videos
58 files
205 links
@R_Experts
🔴آمار علم جان بخشیدن به داده‌هاست.
🔷ارتباط با ما
@iamrezaei
لینک یوتیوب و اینستاگرام و ویرگول:
https://zil.ink/expertstv
Download Telegram
> school = painters$School      # the painter schools 
> school.freq = table(school) # apply the table function
> school.freq
school
A B C D E F G H
10 6 6 10 7 4 7 4
> cbind(school.freq)
school.freq
A 10
B 6
C 6
D 10
E 7
F 4
G 7
H 4


همان طور که مشاهده میکنید جدول فراوانی بین تعداد نقاشان و سطح جایی که اموزش دیدن رو اوردیم و به یک جدول تبدیل کردیم
و این جدول رو سپس ستونی نمودیم
مثلا
A 10
نشان دهنده ی این است که در سطح اموزش A
10 نفر اموزش دیدند


@R_Experts
> school.relfreq = school.freq / nrow(painters) 

> school.relfreq 

school 

       A        B        C        D        E        F 

0.185185 0.111111 0.111111 0.185185 0.129630 0.074074 

       G        H 

0.129630 0.074074

> barplot(school.freq)  

> colors = c("red", "yellow", "green", "violet", 

+   "orange", "blue", "pink", "cyan") 

> barplot(school.freq,         # apply the barplot function 

+   col=colors)                # set the color palette 


ابتدا فراوانی نسبی این داده ها را محاسبه و سپس نمودار هیستوگرام انها را رسم کرد هایم که نمودار ها را در پایین مشاهده میکنید 👇👇👇

@R_Experts
> pie(school.freq)      
> colors = c("red", "yellow", "green", "violet",
+ "orange", "blue", "pink", "cyan")
> pie(school.freq, # apply the pie function
+ col=colors) # set the color palette


نمودار دایره ای مربوطه👇👇👇👇

@R_Experts
#Solution_Practice_3

> cc<-c(1,2,3,4,5,2,1,2,3,4,3,2,1,2,3,4,3,2,1,2,5,4,3,2,1)
> A<-matrix(cc,5,5)
> A
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] 2 1 2 3 4
[3,] 3 2 1 2 3
[4,] 4 3 2 1 2
[5,] 5 4 3 2 1
> b<-matrix(c(7,-1,-3,5,17),5,1)
> b
[,1]
[1,] 7
[2,] -1
[3,] -3
[4,] 5
[5,] 17
> x<-solve(A)%*%b
> x
[,1]
[1,] -2
[2,] 3
[3,] 5
[4,] 2
[5,] -4
#factor_function
فرم کلی این تابع به صورت :
factor(x = character(), levels, labels = levels,
exclude = NA, ordered = is.ordered(x))

که از یک رشته شی محتويات انها را خارج و در
Levels
قرار میدهد و میتوان به انها برچسب نیز نسبت داد ، و ordered ترتیب را برای ما مشخص میکند

> mons = c("March","April","January","November","January",
+ "September","October","September","November","August",
+ "January","November","November","February","May","August",
+ "July","December","August","August","September","November",
+ "February","April")
> mons = factor(mons)
> table(mons)
mons
April August December February January July
2 4 1 2 3 1
March May November October September
1 1 5 1 3

ordered=TRUE

ترتیب اعضای فاکتور را مشخص میکند

> fert = c(10,20,20,50,10,20,10,50,20)
> fert = factor(fert,levels=c(10,20,50),ordered=TRUE)
> fert
[1] 10 20 20 50 10 20 10 50 20
Levels: 10 < 20 < 50


@R_Experts
#abs


abs(x)



x: Numeric value, array or vector

> abs(-1)

[1] 1


> abs(20)

[1] 20


> abs(0)

[1] 0


> x <- c(-2,4,0,45,9,-4)
> abs(x)

[1] 2 4 0 45 9 4


> x <- matrix(c(-3,5,-7,1,-9,4),nrow=3,ncol=2,byrow=TRUE)
> abs(x[1,])

[1] 3 5


> abs(x[,1])

[1] 3 7 9



@R_Experts
#atan

atan() function returns the radian arctangent of number data.

atan(x)



x: Numeric value, array or vector

> atan(1)

[1] 0.7853982


> atan(0)

[1] 0


> atan(0.5)

[1] 0.4636476


> x <- c(1, 0, 0.5)
> atan(x)

[1] 0.7853982 0.0000000 0.4636476


@R_Experts
#beta


beta() function return the beta function and the natural logarithm of the beta function.

B(a,b) = Γ(a)Γ(b)/Γ(a+b)

beta(a, b)

a,b: non-negative numeric vectors

> beta(4,9)

[1] 0.0005050505



> x <- c(3,6, 4)
> y <- c(7,4, 12)
> beta(x,y)

[1] 0.0039682540 0.0019841270 0.0001831502


@R_Experts
#choose()



choose(n,r)


n: n elements
r: r subset elements
...

nCr = n!/(r! * (n-r)!)

> choose(5,2)

[1] 10


> choose(2,1)

[1] 2


@R_Experts
#log( )

function computes natural logarithms (Ln) for a number or vector. log10 computes common logarithms (Lg).log2 computes binary logarithms (Log2). log(x,b) computes logarithms with base b.

>log(5)     #ln5

[1] 1.609438


>log10(5) #lg5

[1] 0.69897


>log2(5) #log25

[1] 2.321928


>log(9,base=3) #log39 = 2

[1] 2


>x <- rep(1:12)
>x

[1] 1 2 3 4 5 6 7 8 9 10 11 12


>log(x)

[1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595 1.9459101
[8] 2.0794415 2.1972246 2.3025851 2.3978953 2.4849066


>log(x,6)

[1] 0.0000000 0.3868528 0.6131472 0.7737056 0.8982444 1.0000000 1.0860331
[8] 1.1605584 1.2262944 1.2850972 1.3382908 1.3868528

@R_Experts
log10() function computes base 10 logarithm.

log10(x)



x: numeric vector


> log10(100)

[1] 2


> x <- c(100,1000, 10000)
> log10(x)

[1] 2 3 4


@R_Experts
#exp


exp(x) function compute the exponential value of a number or number vector, ex.

> x <- 5

> exp(x)


[1] 148.4132



> y <- rep(1:20)

> exp(y)


         [,1]     [,2]     [,3]     [,4]      [,5]

[1,] 2.718282 20.08554 148.4132 1096.633  8103.084

[2,] 7.389056 54.59815 403.4288 2980.958 22026.466


expm1() function computes exp() minus 1:»>حاصل منهای 1

> expm1(5)


[1] 147.4132



> expm1(rep(1:20))


         [,1]     [,2]     [,3]     [,4]      [,5]

[1,] 1.718282 19.08554 147.4132 1095.633  8102.084

[2,] 6.389056 53.59815 402.4288 2979.958 22025.466


@R_Experts
#factorial

factorial() function computes the factorial of a number.

factorial(x)


x: numeric vector


> factorial(2)  #2 × 1

[1] 2


> factorial(1) #1 × 1

[1] 1


> factorial(3) #3 × 2 × 1

[1] 6


> factorial(4) #4 × 3 × 2 × 1

[1] 24


> factorial(c(4,3,2))

[1] 24 6 2


@R_Experts
#max_min

max() function computes the maximun value of a vector. min() function computes the minimum value of a vector.

max(x,na.rm=FALSE)
min(x,na.rm=FALSE)


• x: number vector
• na.rm: whether NA should be removed, if not, NA will be returned
...

> x <- c(1,2.3,2,3,4,8,12,43,-4,-1)
> max(x)

[1] 43


> min(x)

[1] -4


Missing value affect the results:

> y<- c(x,NA)
> y

[1] 1.0 2.3 2.0 3.0 4.0 8.0 12.0 43.0 -4.0 -1.0 NA

> max(y)

[1] NA

> min(y)

[1] NA


After define na.rm=TRUE, result is meaningful:

> max(y,na.rm=TRUE)

[1] 43



Compare more than 1 vectors:

> x2 <- c(-100,-43,0,3,1,-3)
> min(x,x2)

[1] -100

@R_Experts
#atan2

atan2(y, x) function returns the radian arctangent between the x-axis and the vector from the origin to (x, y).


در مختصات دکارتی این نقطه نسبت به مبدا زاویه ای تولید میکند را تانژانت معکوس رادیانش را بر میگرداند
atans(y, x)


x, y: Numeric value, array or vector

> atan2(2,1)

[1] 1.107149


> y <- c(2,3)
> x <- c(5,6)
> atan2(y,x)

[1] 0.3805064 0.4636476


@R_Experts
#cos


cos() function computes the cosine value of numeric value.

cos(x)

x: Numeric value, array or vector

> cos(pi)

[1] -1


> cos(-pi)

[1] -1


> cos(pi/3)

[1] 0.5


> cos(0)

[1] 1


> x <- c(pi, pi/4, pi/3)
> cos(x)

[1] -1.0000000 0.7071068 0.5000000

@R_Experts
#acos

acos() function returns the radian arccosine of number data.

acos(x)


x: Numeric value, array or vector

> acos(1)

[1] 0


> acos(0)

[1] 1.570796


> x <- c(-1,-0.866025,-0.707107,-0.5,0,0.5,0.707107,0.866025,1)
> acos(x)

[1] 3.1415926 2.6179931 2.3561948 2.0943951 1.5707963 1.0471976 0.7853979
[8] 0.5235996 0.0000000

@R_Experts