| To: | mandans_p@yahoo.com |
|---|---|
| Subject: | Re: Function with dataframe argument variables.? |
| From: | David L Lorenz <lorenz@usgs.gov> |
| Date: | Tue, 16 Dec 2008 07:56:58 -0600 |
| Cc: | s-news@lists.biostat.wustl.edu, s-news-owner@lists.biostat.wustl.edu |
| In-reply-to: | <323783.86921.qm@web56001.mail.re3.yahoo.com> |
|
There may be some elegant way to do this, but this will work. The idea is to convert the name in Variable1 to a character string. Dave VarianceT1 <- function(Data, Variable1) { Variable1 <- deparse(substitute(Variable1)) return(mean(Data[[Variable1]])) }
Hi Everyone, I have quick question regarding writing a function for a dataframe with arguments called from the dataframe name. Here is what I am trying to get a simple mean. my question how do address the Data$Variable1 with an argument Variable passed into the function.? ------------------------------- VarianceT1 <- function(Data, Variable1) { if(!is.data.frame(Data)) stop("Data should be a dataframe") if(dim(Data)[1] != length(Data$Variable1)) stop("Data and Variable1 should be of the same length") a1 <- mean(Data$Variable1) return(a1) } -------------------------------- Appreciate all your help and thanks for all shared ideas out there on s-news archive. Thanks a bunch. Thanks -------------------------------------------------------------------- This message was distributed by s-news@lists.biostat.wustl.edu. To unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with the BODY of the message: unsubscribe s-news |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Function with dataframe argument variables.?, Mandans |
|---|---|
| Next by Date: | Re: Function with dataframe argument variables.?, Alan Hochberg |
| Previous by Thread: | Function with dataframe argument variables.?, Mandans |
| Next by Thread: | Re: Function with dataframe argument variables.?, Alan Hochberg |
| Indexes: | [Date] [Thread] [Top] [All Lists] |