|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
#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
#sqrt

sqrt() function computes the square root of a numeric vector.

sqrt(x)


x: numeric or complex vector, array


> sqrt(9)

[1] 3


> sqrt(-1)

[1] NaN
Warning message:
In sqrt(-1) : NaNs produced


> sqrt(3+5i)

[1] 2.101303+1.189738i


> sqrt(c(4,9,16))

[1] 2 3 4
#gamma

gamma() function returns the gamma function Γx.


gamma(x): numeric vectors


> gamma(2)

[1] 1


> gamma(3)

[1] 2


> gamma(4)

[1] 6


> gamma(5)

[1] 24


> gamma(6)

[1] 120


> gamma(c(4,5,6))

[1] 6 24 120
#outer

outer() function applies a function to two arrays.

outer(x, y, FUN="*", ...)
x %o% y


x,y: arrays
FUN: function to use on the outer products, default is multiply
...

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


Calculate logarithm value of array x elements using array y as bases:

>outer(x,y,"log")

[,1] [,2]
[1,] 0.000000 0.0000000
[2,] 1.201634 0.6008169
[3,] 1.000000 0.5000000
[4,] 1.584963 0.7924813
[5,] 2.000000 1.0000000
[6,] 3.000000 1.5000000
[7,] 3.584963 1.7924813
[8,] 5.426265 2.7131324


Add array x elements with array y elements:

> outer(x,y,"+")

[,1] [,2]
[1,] 3.0 5.0
[2,] 4.3 6.3
[3,] 4.0 6.0
[4,] 5.0 7.0
[5,] 6.0 8.0
[6,] 10.0 12.0
[7,] 14.0 16.0
[8,] 45.0 47.0


Multiply array x elements with array y elements:

> x %o% y  #equal to outer(x,y,"*")

[,1] [,2]
[1,] 2.0 4.0
[2,] 4.6 9.2
[3,] 4.0 8.0
[4,] 6.0 12.0
[5,] 8.0 16.0
[6,] 16.0 32.0
[7,] 24.0 48.0
[8,] 86.0 172.0


Concatenate characters to the array elements:

>z <- c("a","b")
>outer(x,z,"paste")

[,1] [,2]
[1,] "1 a" "1 b"
[2,] "2.3 a" "2.3 b"
[3,] "2 a" "2 b"
[4,] "3 a" "3 b"
[5,] "4 a" "4 b"
[6,] "8 a" "8 b"
[7,] "12 a" "12 b"
[8,] "43 a" "43 b"


@R_Experts
#svd

svd() function computes the singular-value decomposition of a rectangular matrix.

svd(x, nu = min(n, p), nv = min(n, p), LINPACK = FALSE)
La.svd(x, nu = min(n, p), nv = min(n, p))


x: a numeric, logical or complex matrix
nu: the number of left singular vectors to be computed. This must between 0 and n = nrow(x)
nv: the number of right singular vectors to be computed. This must be between 0 and p = ncol(x)
LINPACK: logical. Should LINPACK be used (for compatibility with R < 1.7.0)? In this case nu must be 0, nrow(x) or ncol(x)


> x <- matrix(1:16,4,4)
> x

[,1] [,2] [,3] [,4]
[1,] 1 5 9 13
[2,] 2 6 10 14
[3,] 3 7 11 15
[4,] 4 8 12 16


> svd(x)

$d
[1] 3.862266e+01 2.071323e+00 2.076990e-15 4.119458e-16

$u
[,1] [,2] [,3] [,4]
[1,] -0.4284124 -0.7186535 0.43803202 0.3288281
[2,] -0.4743725 -0.2738078 -0.82913672 -0.1119477
[3,] -0.5203326 0.1710379 0.34417739 -0.7625890
[4,] -0.5662928 0.6158835 0.04692732 0.5457086

$v
[,1] [,2] [,3] [,4]
[1,] -0.1347221 0.82574206 0.5322301 -0.1293488
[2,] -0.3407577 0.42881720 -0.6132292 0.5691660
[3,] -0.5467933 0.03189234 -0.3702319 -0.7502855
[4,] -0.7528288 -0.36503251 0.4512310 0.3104683

@R_Experts
#diag

diag() function extracts or replaces the diagonal of a matrix, or constructs a diagonal matrix.

diag(x = 1, nrow, ncol)

diag(x) <- value


x: matrix, vector
nrow, ncol: Optional dimensions for the result when x is not a matrix
: either a single value or a vector of length equal to that of the current diagonal. Should be of a mode which can be coerced to that of x
...

> diag(10,3,4)


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

[1,]   10    0    0    0

[2,]    0   10    0    0

[3,]    0    0   10    0



> diag(3)


     [,1] [,2] [,3]

[1,]    1    0    0

[2,]    0    1    0

[3,]    0    0    1


@R_Experts
#dim


dim() function gets or sets the dimension of a matrix, array or data frame.

dim(x)


x: array, matrix or data frame.

>BOD #R Biochemical Oxygen Demand Dataset

Time demand
1 1 8.3
2 2 10.3
3 3 19.0
4 4 16.0
5 5 15.6
6 7 19.8


>class(BOD)

[1] "data.frame"


>dim(BOD) #get dimension

[1] 6 2


Set dimension of a matrix:

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

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


Set dimension to 2 × 5:
>dim(x) <- c(2,5)
>x

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


@R_Experts
#prod

prod() function returns the multiplication results of all the values present in its arguments.

prod(..., na.rm=FALSE)


...: numeric or complex or logical vectors
na.rm: whether missing values be removed or not
...

> prod(4:6) #4 × 5 × 6

[1] 120


> x <- c(3.2,5,4.3)
> prod(x) #3.2 × 5 × 4.3

[1] 68.8

@R_Experts
#crossprod
دستوری که یک ماتریس دلخواه را از چپ و راست در ترانهاده اش ضرب میکند

crossprod() function returns matrix cross-product.

crossprod(x, y = NULL)
tcrossprod(x, y = NULL)


x: numeric matrix
y: numeric matrix, if y=NULL, y is the same as x
...

> x <- matrix(1:9,3,3)
> x

[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9


> crossprod(x)
>t(x)%*%x
[,1] [,2] [,3]
[1,] 14 32 50
[2,] 32 77 122
[3,] 50 122 194


> tcrossprod(x)
x%*%t(x)
[,1] [,2] [,3]
[1,] 66 78 90
[2,] 78 93 108
[3,] 90 108 126

@R_Experts
#which

which() function gives the TRUE indices of a logical object, allowing for array indices.

which(x, arr.ind = FALSE, useNames = TRUE)
arrayInd(ind, .dim, .dimnames = NULL, useNames = FALSE)


x: logical vector or array. NAs are allowed and omitted (treated as if FALSE)
arr.ind: logical; should array indices be returned when x is an array?
ind: integer-valued index vector, as resulting from which(x)
.dim: integer vector
.dimnames: optional list of character dimnames(.), of which only .dimnames[[1]] is used
useNames: logical indicating if the value of arrayInd() should have (non-null) dimnames at all


> which(letters=="h")

[1] 8


> BOD

Time demand
1 1 8.3
2 2 10.3
3 3 19.0
4 4 16.0
5 5 15.6
6 7 19.8


> which(BOD$demand == 16)

[1] 4


> x <- matrix(1:9,3,3)
> x

[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9


> which(x %% 3 == 0, arr.ind=TRUE)

row col
[1,] 3 1
[2,] 3 2
[3,] 3 3


> which(x %% 3 == 0, arr.ind=FALSE)

[1] 3 6 9


@R_Experts
#R_Experts

vector1 <- c(5,9,3)
vector2 <- c(10,11,12,13,14,15)
column.names <- c("COL1","COL2","COL3")
row.names <- c("ROW1","ROW2","ROW3")
matrix.names <- c("Matrix1","Matrix2")

#R_Experts:#Take these vectors as input to the array.
result <- array(c(vector1,vector2),dim = c(3,3,2),dimnames = list(row.names,column.names,
matrix.names))
print(result)

#R_Experts

👆👆👆👆👆

@R_Experts
#R_Date_&_Time_Functions
در این نرم افزار چندین نوع #تاریخ و #زمان وحود دارد که در تابع مختلف موجود می باشند .

data()

تابعی است که تاریخ وزمان را به صورت یک رشته کاراکتر باز میگرداند .

 Sys.Date() 

که تاریخ سیستم را به صورت یک فرمت عادی
زمان نشان میدهد

Sys.time()

که تاریخ و زمان سیستم را نمایش میدهد

#نکته :کلاس هر یک از این توابع مختلف است


@R_Experts