Syzygy

Tuesday, February 7, 2012

Why I hate programming (part 4 of n)

back to R:

1. Writing some code, seemed a bit slow, looked to stack overflow for help:
"First of all, for anyone who hasn't seen this yet, I strongly recommend reading this article on the r-wiki about code optimization."

status of link: dead
reason: R's wiki page is dead

2. Populating a matrix from a vector. (In R, a matrix is different from an array is different from a vector.)

vec <- 1:9
mat <- as.matrix(vec, nrow = 3, ncol = 3)
# mat is 9x1 (silent fail on invalid arguments nrow and ncol)
mat2 <- matrix(vec, nrow = 3, ncol = 3)
# mat2 is 3x3

3. How big is my vector?

vec <- 1:9
mat2 <- as.matrix(vec, nrow = 3, ncol = 3)
nrow(vec) # NULL
nrow(mat2) # 3
NROW(vec) # 3
NROW(mat2) # 3

Labels: , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home