Skip to content
Prev 365884 / 398502 Next

Write a function that allows access to columns of a passeddataframe.

Perhaps the best way is the one used by library(), where both 
library(package) and library("package") work. It uses 
as.charecter/substitute, not deparse/substitute, as follows.

mydf <- 
data.frame(id=c(1,2,3,4,5),sex=c("M","M","M","F","F"),age=c(20,34,43,32,21))
mydf
class(mydf)
str(mydf)

myfun <- function(frame,var){
	yy <- as.character(substitute(var))
	frame[, yy]
}

myfun(mydf, age)
myfun(mydf, "age")

Rui Barradas

Em 06-12-2016 15:03, William Dunlap escreveu:

Thread (21 messages)

John Sorkin Write a function that allows access to columns of a passed dataframe. Dec 5 Rui Barradas Write a function that allows access to columns of a passed dataframe. Dec 5 Rui Barradas Write a function that allows access to columns of a passed dataframe. Dec 5 John Sorkin Write a function that allows access to columns of a passed dataframe. Dec 5 Bert Gunter Write a function that allows access to columns of a passed dataframe. Dec 5 Rui Barradas Write a function that allows access to columns of a passed dataframe. Dec 5 Rui Barradas Write a function that allows access to columns of a passed dataframe. Dec 5 David Winsemius Write a function that allows access to columns of a passed dataframe. Dec 5 Rui Barradas Write a function that allows access to columns of a passed dataframe. Dec 5 David Winsemius Write a function that allows access to columns of a passed dataframe. Dec 5 Bert Gunter Write a function that allows access to columns of a passed dataframe. Dec 5 Bert Gunter Write a function that allows access to columns of a passed dataframe. Dec 5 Bert Gunter Write a function that allows access to columns of a passed dataframe. Dec 5 Rui Barradas Write a function that allows access to columns of a passed dataframe. Dec 6 John Sorkin Write a function that allows access to columns of a passeddataframe. Dec 6 Rui Barradas Write a function that allows access to columns of a passeddataframe. Dec 6 William Dunlap Write a function that allows access to columns of a passeddataframe. Dec 6 Rui Barradas Write a function that allows access to columns of a passeddataframe. Dec 6 William Dunlap Write a function that allows access to columns of a passeddataframe. Dec 6 David Winsemius Write a function that allows access to columns of a passeddataframe. Dec 6 Bert Gunter Write a function that allows access to columns of a passeddataframe. Dec 6