[R] quotation problem/dataframe names as function input argument.
dwinsemius at comcast.net
Tue Dec 23 22:16:29 CET 2008
I think you are making it too hard. See if one of these is a path to
the answer you seek:
1 1 2
> n.obs <- function(x) dim(x)
 1 2
> ng.obs <- function(x) dim(get(x))
 1 2
> ng1.obs <- function(x) dim(get(x))
 1 1
On Dec 23, 2008, at 3:53 PM, Sean Zhang wrote:
> Dear R friends:
> Can someone help me with the following problem? Many thanks in
> # Problem Description:
> # I want to write functions which take a (character) vector of
> names as input argument.
> # For example, I want to extract the number of observations from a
> number of
> # I tried the following:
> nobs.fun <- function (dframe.vec)
> nobs.vec <- array(NA,c(length(dframe.vec),1))
> for (i in 1:length(dframe.vec))
> nobs.vec[i] <- dim(dframe.vec[i])
> # To show the problem, I create a fake dataframe and store its name
> # in a vector (i.e., dframe.vec) of length 1.
> # creation of fake dataframe
> dframe.1 <- as.data.frame(matrix(seq(1:2),c(1,2)))
> # store the dataframe name into a vector using c() function
> dframe.vec <- c("dframe.1")
> # The problem is that the following line does not work
> # Seems to me, the problem stems from the fact that dframe.vec is
> intepreted by R as "dframe.vec" (note: it is quotated)
> # and dim("dframe.vec") gives NULL.
> # Also, I realize the following line works as expected (note: dframe.
> 1 is
> not quoted any more):
> So my question is then: how can I pass dataframe names as an input
> for another function
> without running into the quotation mark issue above?
> Any hint?
> Thank you in advance.
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help