2019년 6월 19일 수요일

R: Matrices

1. 행의 합 구하기

1
2
3
4
5
6
7
8
9
10
11
12
13
> # Construct star_wars_matrix
> box_office <- c(460.998, 314.4, 290.475, 247.900, 309.306, 165.8)
> star_wars_matrix <- matrix(box_office, nrow = 3, byrow = TRUE,
                             dimnames = list(c("A New Hope", "The Empire Strikes Back", "Return of the Jedi"), 
                                             c("US", "non-US")))
> # dimnames: 리스트의 첫 번째가 rownames, 두 번째가 colnames
> # Calculate worldwide box office figures
> worldwide_vector <- rowSums(star_wars_matrix)
> worldwide_vector
             A New Hope The Empire Strikes Back      Return of the Jedi 
                775.398                 538.375                 475.106
cs

※ 워크스페이스에 저장된 내용 조회하기

1
2
> ls()
[1] "star_wars_matrix"  "star_wars_matrix2"
cs

※ 열의 합은 colSums() 함수를 사용한다.



댓글 없음:

댓글 쓰기