<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix"><br>
      Hi,<br>
      <br>
      It's easier to use get() to fetch column names dynamically. 
      eval() is more for when you want to construct the 'j' or 'by'
      clause dynamically and you need to eval the whole argument; e.g.
      DT[, eval(...), eval(...)]<br>
      <br>
      In your example,<br>
      <br>
      i <- "east2a"<br>
      temp1 <- paste(i)<br>
      temp2 <- paste0("east2b.", 1)<br>
      accounts[ , CrossTable(get(temp1), get(temp2), expected = FALSE,
      prop.chisq = FALSE, prop.c = FALSE)]<br>
      <br>
      I guess you're placing CrossTable in j like that because you want
      to do this by group next?  If not,  just use data.table as you
      would a data.frame for this part.  It doesn't seem CrossTable has
      a 'data' argument but you could pass data.table to y (since
      data.table is a data.frame too).<br>
      <br>
      HTH, Matt<br>
      <br>
      <br>
      On 10/03/14 01:18, Paul Johnson wrote:<br>
    </div>
    <blockquote
cite="mid:CAErODj_Ud4oLDD1P7UkG8Fgn9+8gayRWwAP_AbxEaqeEjbRO_Q@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>Hi<br>
          <br>
        </div>
        I've been using data.table only 1 week. Some of the idioms still
        have me befuddled.  I'm finding some things that work, and I
        don't understand why. That's bad, but more frustrating, I have
        usages that seem good, but fail.  I manage the aggregation on
        subsets parts more easily than the seemingly easier chores where
        I want to treat this as a data frame.<br>
        <div>
          <div><br>
          </div>
          <div>In this example, accounts is a huge data.table with
            41,000 lines, I'm pasting in a little dump of a few lines
            below, if it gives you enough to test.<br>
          </div>
          <div><br>
            ## This works:<br>
            library(gmodels)<br>
            temp1 <- quote(east2a)<br>
            temp2 <- quote(east2b.1)<br>
            accounts[ , CrossTable(eval(temp1), eval(temp2), expected =
            FALSE, prop.chisq = FALSE, prop.c = FALSE)]<br clear="all">
            <br>
            <br>
            ## why does this not work?<br>
            i <- "east2a"<br>
            temp1 <- quote(paste(i))<br>
            temp2 <- quote(paste0("east2b.", 1))<br>
            accounts[ , CrossTable(eval(temp1), eval(temp2), expected =
            FALSE, prop.chisq = FALSE, prop.c = FALSE)]<br>
            <br>
          </div>
          <div>Here's what happens when I run that:<br>
            <br>
            > library(gmodels)<br>
            > temp1 <- quote(east2a)<br>
            > temp2 <- quote(east2b.1)<br>
            > accounts[ , CrossTable(eval(temp1), eval(temp2),
            expected = FALSE, prop.chisq = FALSE, prop.c = FALSE)]<br>
            <br>
             <br>
               Cell Contents<br>
            |-------------------------|<br>
            |                       N |<br>
            |           N / Row Total |<br>
            |         N / Table Total |<br>
            |-------------------------|<br>
            <br>
             <br>
            Total Observations in Table:  41052 <br>
            <br>
             <br>
                         | east2b.1 <br>
                  east2a |       Yes |        No | Row Total | <br>
            -------------|-----------|-----------|-----------|<br>
                     Yes |      9703 |      3051 |     12754 | <br>
                         |     0.761 |     0.239 |     0.311 | <br>
                         |     0.236 |     0.074 |           | <br>
            -------------|-----------|-----------|-----------|<br>
                      No |      7957 |     20341 |     28298 | <br>
                         |     0.281 |     0.719 |     0.689 | <br>
                         |     0.194 |     0.495 |           | <br>
            -------------|-----------|-----------|-----------|<br>
            Column Total |     17660 |     23392 |     41052 | <br>
            -------------|-----------|-----------|-----------|<br>
            <br>
             <br>
                   t  prop.row  prop.col   prop.tbl<br>
            1:  9703 0.7607809 0.5494337 0.23635876<br>
            2:  7957 0.2811859 0.4505663 0.19382734<br>
            3:  3051 0.2392191 0.1304292 0.07432037<br>
            4: 20341 0.7188141 0.8695708 0.49549352<br>
            > i <- "east2a"<br>
            > temp1 <- quote(paste(i))<br>
            > temp2 <- quote(paste0("east2b.", 1))<br>
            >  eval(temp2)<br>
            [1] "east2b.1"<br>
            > accounts[ , CrossTable(eval(temp1), eval(temp2),
            expected = FALSE, prop.chisq = FALSE, prop.c = FALSE)]<br>
            Error in chisq.test(t, correct = FALSE) : <br>
              'x' must at least have 2 elements<br>
          </div>
          <div><br>
          </div>
          <div>From the output of dput here, can you reconstruct
            accounts for demonstration? I could drop it in a website/<br>
          </div>
          <div><br>
            > dput(accounts[1:4, .SD])<br>
            structure(list(sippid = c("019003754630:0203",
            "019003754630:0204", <br>
            "019052074737:0101", "019052074737:0102"), east2bFirst =
            c("99", <br>
            "11.0", "04.0", "04.0"), east2b = structure(c(2L, 1L, 1L,
            1L), .Label = c("Yes", <br>
            "No"), class = "factor"), tage = c(19L, 25L, 30L, 29L),
            east2aFirst = c("99", <br>
            "99", "03.0", "03.0"), east2a = structure(c(2L, 2L, 1L, 1L),
            .Label = c("Yes", <br>
            "No"), class = "factor"), east2b.1 = structure(c(2L, 2L, 2L,
            <br>
            2L), .Label = c("Yes", "No"), class = "factor"), tage.1 =
            c(19L, <br>
            22L, 30L, 28L), east3bFirst = c("99", "99", "03.0", "03.0"),
            <br>
                east3b = structure(c(2L, 2L, 1L, 1L), .Label = c("Yes",
            "No"<br>
                ), class = "factor"), east2b.2 = structure(c(2L, 2L, 2L,
            <br>
                2L), .Label = c("Yes", "No"), class = "factor"), tage.2
            = c(19L, <br>
                22L, 30L, 28L), east1aFirst = c("99", "99", "11.0",
            "11.0"<br>
                ), east1a = structure(c(2L, 2L, 1L, 1L), .Label =
            c("Yes", <br>
                "No"), class = "factor"), east2b.3 = structure(c(2L, 2L,
            <br>
                1L, 1L), .Label = c("Yes", "No"), class = "factor"),
            tage.3 = c(19L, <br>
                22L, 32L, 31L), east3aFirst = c("99", "99", "11.0",
            "11.0"<br>
                ), east3a = structure(c(2L, 2L, 1L, 1L), .Label =
            c("Yes", <br>
                "No"), class = "factor"), east2b.4 = structure(c(2L, 2L,
            <br>
                1L, 1L), .Label = c("Yes", "No"), class = "factor"),
            tage.4 = c(19L, <br>
                22L, 32L, 31L), east2cFirst = c("99", "99", "99", "99"),
            <br>
                east2c = structure(c(2L, 2L, 2L, 2L), .Label = c("Yes",
            "No"<br>
                ), class = "factor"), east2b.5 = structure(c(2L, 2L, 2L,
            <br>
                2L), .Label = c("Yes", "No"), class = "factor"), tage.5
            = c(19L, <br>
                22L, 29L, 28L), east1bcFirst = c("99", "99", "08.0",
            "09.0"<br>
                ), east1bc = structure(c(2L, 2L, 1L, 1L), .Label =
            c("Yes", <br>
                "No"), class = "factor"), east2b.6 = structure(c(2L, 2L,
            <br>
                1L, 1L), .Label = c("Yes", "No"), class = "factor"),
            tage.6 = c(19L, <br>
                22L, 31L, 30L), east2dFirst = c("99", "99", "99", "99"),
            <br>
                east2d = structure(c(2L, 2L, 2L, 2L), .Label = c("Yes",
            "No"<br>
                ), class = "factor"), east2b.7 = structure(c(2L, 2L, 2L,
            <br>
                2L), .Label = c("Yes", "No"), class = "factor"), tage.7
            = c(19L, <br>
                22L, 29L, 28L)), .Names = c("sippid", "east2bFirst",
            "east2b", <br>
            "tage", "east2aFirst", "east2a", "east2b.1", "tage.1",
            "east3bFirst", <br>
            "east3b", "east2b.2", "tage.2", "east1aFirst", "east1a",
            "east2b.3", <br>
            "tage.3", "east3aFirst", "east3a", "east2b.4", "tage.4",
            "east2cFirst", <br>
            "east2c", "east2b.5", "tage.5", "east1bcFirst", "east1bc",
            "east2b.6", <br>
            "tage.6", "east2dFirst", "east2d", "east2b.7", "tage.7"),
            sorted = "sippid", class = c("data.table", <br>
            "data.frame"), row.names = c(NA, -4L), .internal.selfref =
            <pointer: 0x1df8f58>)<br>
            <br>
            <br>
            <br>
            <br>
            -- <br>
            Paul E. Johnson<br>
            Professor, Political Science      Assoc. Director<br>
            1541 Lilac Lane, Room 504      Center for Research Methods<br>
            University of Kansas                 University of Kansas<br>
            <a moz-do-not-send="true" href="http://pj.freefaculty.org"
              target="_blank">http://pj.freefaculty.org</a>            
              <a moz-do-not-send="true" href="http://quant.ku.edu"
              target="_blank">http://quant.ku.edu</a>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
datatable-help mailing list
<a class="moz-txt-link-abbreviated" href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a>
<a class="moz-txt-link-freetext" href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a></pre>
    </blockquote>
    <br>
  </body>
</html>