Forgive my newbie question. I only got started using R since a month ago. This is similar to the question here Strings as variable references in an R formula
Since I can't comment on the answer, I'll just post it here.
I have a dataframe called dataxl
. In this code, I am using the crosstab()
function from http://pcwww.liv.ac.uk/~william/R/crosstab.r. (You can see the explanation of the code here http://rstudio-pubs-static.s3.amazonaws.com/6975_c4943349b6174f448104a5513fed59a9.html) After running the code below, an organized version of CrossTable()
function output will be shown:
ct1 <- crosstab(dataxl, row.vars = "dataxl.tipe_merchant", col.vars = "dataxl.status", type = c("f","t"), style = "wide", addmargins = TRUE)
I am trying to read row.vars
from a string variable that stores "dataxl.tipe_merchant"
, let's call it name. I have tried the following:
name <- paste("dataxl.", "tipe_merchant", sep="")
f <- formula(name)
ct1 <- crosstab(dataxl, row.vars = f, col.vars = "dataxl.status", type = c("f","t"), style = "wide", addmargins = TRUE)
but it keeps saying something around the line
Error in eval(parse(text = x, keep.source = FALSE)[[1L]]) :
object 'dataxl.tipe_merchant' not found
....something around object 'dataxl.tipe_merchant'
not found. Why is this so? Thank you!