Today I am going to introduce one of the important concepts of R , the Vector
Before taking up to the main subject, I have to say that, R is also programming language which has diverse statistic functions. As other languages did, R code has a variable and assignment grammar.
I think universal grammar of assignment is "="
However R provide another assignment expression "<-"
> I = 1
> I = I+2
> I
[1] 3
> I <- 1
> I = I+4
> I
[1] 5
Now move on to the highlight,
R use a column vector in order to manipulate a data set. The form of column vector is similar to column matrix.
Definition of Vector is "collection of numeric, character or Logical values"
In other words, one vector can contain only one data type. If you try to contain diverse datatype such as numeric (1,2,3,4) and characters ("KOREA","USA","CANADA") at the same time, numeric data set will be converted into a character data type ("1","2","3","4")
Let's look at the sample below
# c ( 1,2,3) : c stands for concatenation ,
> c (1,2,3,4)
[1] 1 2 3 4
> c("KOREA","CANADA")
[1] "KOREA" "CANADA"
> c( 1,2,3,"KOREA")
[1] "1" "2" "3" "KOREA"
> c (T,T)
[1] TRUE TRUE
> c (T,T, 1,2)
[1] 1 1 1 2
> c (T,T, "KOREA")
[1] "TRUE" "TRUE" "KOREA"
> A = c(T,T,"KOREA")
> B = c(T,T,1,2)
> C = c(A,B)
> C
[1] "TRUE" "TRUE" "KOREA" "1" "1" "1" "2"
> C[1]
[1] "TRUE"
> C[19]
[1] NA
댓글 없음:
댓글 쓰기