[R] Tying to underdressed the magic of lm redux

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Thu May 30 03:40:09 CEST 2019


Thanks to several kind people, I understand how to use deparse(substitute(paramter)) to get as text strings the arguments passed to an R function. What I still can't do is put the text strings recovered by deparse(substitute(parameter)) back together to get the columns of a dataframe passed to the function. What I want to do is pass a column name to a function along with the name of the dataframe and then, within the function access the column of the dataframe.

I want the function below to print the columns of the dataframe testdata, i.e. testdata[,"FSG"] and testdata[,"GCM"]. I have tried several ways to tell the function to print the columns; none of them work.

I thank everyone who has helped in the past, and those people who will help me now!

John

testdata <- structure(list(FSG = c(271L, 288L, 269L, 297L, 311L, 217L, 235L,

                                   172L, 201L, 162L), CGM = c(205L, 273L, 226L, 235L, 311L, 201L,

                                   203L, 155L, 182L, 163L)), row.names = c(NA, 10L), class = "data.frame")

cat("This is the data frame")

class(testdata)

testdata



BAPlot <- function(first,second,indata){

  # these lines of code work

    col1 <- deparse(substitute(first))

    col2 <- deparse(substitute(second))

    thedata <- deparse(substitute(third))

    print(col1)

    print(col2)

    print(thedata)

    cat("This gets the data, but not as a dataframe\n")

    zoop<-paste(indata)

    print(zoop)

    cat("End This gets the data, but not as a dataframe\n")

     # these lines do not work

    print(indata[,first])

    print(indata[,"first"])

    print(thedata[,col1])

    paste(zoop[,paste(first)])

    paste(zoop[,first])

    zap<-paste(first)

    print(zap)

}




	[[alternative HTML version deleted]]



More information about the R-help mailing list