简体   繁体   中英

use variable name instead of column name in R function

In this:

y <- svytable(~date4a, design = Pew.w)

date4a is a column name.

I want to replace date4a with a variable. The variable of course, will refer to a column name.

Eg something like:

col <- "date4a"

y <- svytable(~col, design = Pew.w)   #This doesnt' work

How may I do that?

Under the assumption that this is something that is really worth doing, you could try:

col <- my.data.frame$date4a
y   <- svytable(~col, design=Pew.w)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM