Skip to content
Prev 246006 / 398503 Next

access a column of a dataframe without qualifying the name of the column

Thank you
John




John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> Bert Gunter <gunter.berton at gene.com> 12/29/2010 8:17 PM >>>
?substitute

test <- function(col,frm) {
  eval(substitute(col),frm)
}

test2 <- function(col,frm){
  cname<- deparse(substitute(col))
  frm[[cname]]
}

 z <- data.frame(x=1:3,y=letters[1:3])

test(x, z)

test2(x, z)


-- Bert
On Wed, Dec 29, 2010 at 4:44 PM, David Winsemius <dwinsemius at comcast.net> wrote: