d <- c(값, 값, ...)
x <- factor(c(값, 값, ...))
colors <- factor(c("RED","BLUE","GREEN","BLUE","YELLOW","BLACK"))
MR <- matrix(1:9 ,nrow = 3 ,ncol = 3)
MR
//결과
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
human <- data.frame(name = c("Tom", "Jane" , "Patric"),
gender = c("M","W","M"),
height = c(180,160,175),
student = c(TRUE, TRUE, FALSE),
num = c(1:3))
human
//결과
name gender height student num
1 Tom M 180 TRUE 1
2 Jane W 160 TRUE 2
3 Patric M 175 FALSE 3
인덱스는 0이 아닌 1 부터 시작
인덱스를 사용하고자 할 땐 []가 아닌 [[]] 두개로 사용해야함
값을 선택할 때 좌표는 [1,2]로 특정한 값을 선택할 수도 있고 [,2]와 같이 2행의 모든 열을 선택할 수도 있다.
d <- c(1,4,3,2)
sort(c , decreasing = TRUE)
TRUE는 내림차순 , FALSE는 오름차순 으로 정렬한다.
byrow는 정렬 방법을 바꿀 수 있다.
defalut값은 내림차순이다.
d <- matri(1:9 , ncol = 3 , nrow = 3 , byrow = T)
1 4 7
2 5 8
3 6 9
//byrow = F
1 2 3
4 5 6
7 8 9
iris 는 R에서 쓰이는 데이터 셋
dim(iris)
nrow(iris)
ncol(iris)
colnames(iris)
rownames(iris)
colSums(iris [ , c(1,2) ] )
colMeans(iris [ c(1,2) , c(1,2) ] )
rowSums(iris [ c(1,2) , (1,2) ] )
rowMeans(iris [ , c(1,2) ] )
t(human)
head(iris)
tail(iris)
class(human)
is.data.frame(human)
is.matrix(human)
> class(human)
[1] "data.frame"
> is.data.frame(human)
[1] TRUE
> is.matrix(human)
[1] FALSE