Wednesday 15 February 2012

How R subtracts a matrix from an integer -



How R subtracts a matrix from an integer -

this question r's internals. curious if explain how next phone call works.

# let's work part of iris info data(iris) df <- iris[1:10, 1:4] # question 1 - df

does r create matrix of equivalent dimensions? loop on elements? how r subtracting matrix integer?

note illustration data.frame , not matrix. refer data.frame case.

an s3 method dispatched ops grouping generic (see methods("ops")). relevant method ops.data.frame. here excerpts comments added me:

#create unevaluated function phone call fun <- get(.generic, envir = parent.frame(), mode = "function") f <- if (unary) quote(fun(left)) else quote(fun(left, right)) #... #a lot of checking , preparations #... #loop on columns, create function input , evaluate function phone call (j in seq_along(cn)) { left <- if (!lscalar) e1[[j]] else e1 right <- if (!rscalar) e2[[j]] else e2 value[[j]] <- eval(f) }

in case of arguments - beingness integer vector , integer matrix, both treated integer vector, .primitive("-") preserves attributes, includes dim atribute of matrix. see help("-").

r matrix

No comments:

Post a Comment