4,547,132 th visitor since 2017.2.1 ( Today : 3524 )
Programming
No. 790
Name. swindler
Subject. R 배열 (벡터, 행렬)
Main Cate. 개발일반
Sub Cate.
Date. 2017-03-22 14:01
Hit. 2012 (121.78.49.66)
File.
> matrix(1:10, nrow=2, ncol=5)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10


> matrix(1:10, nrow=5, ncol=2)
[,1] [,2]
[1,] 1 6
[2,] 2 7
[3,] 3 8
[4,] 4 9
[5,] 5 10


> matrix(1:10, nrow=2, ncol=5, byrow=T)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] 6 7 8 9 10


> matrix(1:10, nrow=5, ncol=2, byrow=T)
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 6
[4,] 7 8
[5,] 9 10

이 시점에서 matrix help를 한번 안 볼수 없다.
?matrix

byrow는 default가 FALSE이고, (TRUE, FALSE를 그냥 T, F로 써도 되나 보다.)

이 시점에서 T와 F를 또 안 해 볼수 없지.
> T
[1] TRUE
> F
[1] FALSE
> T()
Error: could not find function "T"


갑자기, 프로그래밍 언어를 처음 배우던 때가 생각난다.
(사실 그게 생각날리가...198x 년의 일인데...그냥 그렇다는 얘기...)


당연하겠지만, 이 배열을 함수에 저장할수도..

> x<-matrix(1:10,nrow=2,ncol=5)
> x
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10
> y<-matrix(1:10, 2, 5)
> y
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10

> matrix(1:10, 2, 5, T)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] 6 7 8 9 10

해보니, 굳이 nrow=, ncol=, byrow= 이거 안 써도 되는구나.




[바로가기 링크] : http://coolx.net/cboard/develop/790



Name
Password
Comment
Copyright © 1999-2017, swindler. All rights reserved. 367,611 visitor ( 1999.1.8-2004.5.26 ), 2,405,771 ( -2017.01.31)

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog