0

I want to assign a variable, "dv1" that will pass a given variable name into a formula so that I can create dynamic data references.

Code

# Define terms
esto1<-g6e ### temporarily stored variable #1
esto2<-g6c ### temporarily stored variable #2, etc. 
dv1<-"attitude"     ### The dependent variable that you'll be testing
# 
shapiro.test(esto1$dv1)
shapiro.test(esto2$dv1)

# Given esto1=g6e, esto2=g6c, and dv1=attitude, the statements above should be the equivalent of: 
shapiro.test(g6e$attitude)
shapiro.test(g6c$attitude)
Josh
  • 311
  • 3
  • 11

1 Answers1

-1

The following code appears to work:

  # Define terms
esto1<-g6e ### temporarily stored variable #1
esto2<-g6c ### temporarily stored variable #2, etc. 
dv1<-"attitude"     ### The dependent variable that you'll be testing

# attempt 2
shapiro.test(esto1[[dv1]])
shapiro.test(esto2[[dv1]])

# Given esto1=g6e, esto2=g6c, and dv1=attitude, the statements above should be the equivalent of: 
shapiro.test(g6e$attitude)
shapiro.test(g6c$attitude)

I extrapolated from Dynamically select data frame columns using $ and a vector of column names to figure this out.

Josh
  • 311
  • 3
  • 11