<div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div><span></span></div><div></div><div id="yui_3_16_0_1_1449720955480_3234"> Gosh that is simple, elegant and wonderful. Feel kinda sorta silly for not thinking of it. Thank you for enlightening me.</div><div id="yui_3_16_0_1_1449720955480_3425"><br></div><div id="yui_3_16_0_1_1449720955480_3427">My Dad once said if there was a hard way to do a simple task, he was confident I would find it. That malady has stuck with me oh so many years. But in 10 years as an aerospace engineer and 35 as a CPA, there was nothing simple, and an unknown unknown could be devastating. BTW, worked as a programmer(Fortran in the 60's) to pay for college, and did some programming at Lockheed for the flutter group. </div><div id="yui_3_16_0_1_1449720955480_3364">.</div><div id="yui_3_16_0_1_1449720955480_3339">Arun covered chaining in the Data Camp course and I use it frequently. On my personal project I am mired down in data exploration and investigating variable distributions, means, medians, et al. Some behave as expected, others have me scratching my head and muttering. Somewhere somehow it all will make sense, but the big picture is eluding me.</div><div id="yui_3_16_0_1_1449720955480_3463"><br></div><div id="yui_3_16_0_1_1449720955480_3464"><br></div><div class="signature" id="yui_3_16_0_1_1449720955480_3233">Carl Sutton CPA<br><div></div></div> <br><div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font face="Arial" size="2"> On Wednesday, December 9, 2015 6:43 PM, mbacou [via R] <<a href="/user/SendEmail.jtp?type=node&node=4715361&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>> wrote:<br></font></div> <blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' style="padding-left: 5px; margin-top: 5px; margin-left: 5px; border-left-color: rgb(16, 16, 255); border-left-width: 2px; border-left-style: solid;"> <br><br> <div class="y_msg_container"><div id="yiv0923163841">
Carl,
<br>Are you just looking for the following syntax?
<br><br>dt[a<35 & b>35, lapply(.SD, median, na.rm = T), by = d]
<br><br>You can include as many conditions as necessary in `i`. You can also
<br>chain data.tables:
<br><br>dt[a<35][b>35][, lapply(.SD, median, na.rm = T), by = d]
<br><br>--Mel.
<br><br>On 12/9/2015 1:02 PM, carlsutton wrote:
<div class="yiv0923163841shrinkable-quote"><div class='shrinkable-quote'><br>> Is there a way to subset a data table using "i" with multiple criteria using
<br>> multiple variables(columns)? I have some test code shown below on what I
<br>> have tried. And yes, I have read the documentation, taking the data camp
<br>> class (Multiple viewing, I'm a slow learner) and have not seen anything
<br>> relevant. Also checked for questions on this topic in this forum and did
<br>> not find an answer for my query.
<br>> Attempting to upload R file
<br>> dataTableExamples.R
<br>> <<a href="http://r.789695.n4.nabble.com/file/n4715347/dataTableExamples.R" target="_blank" rel="nofollow" link="external">http://r.789695.n4.nabble.com/file/n4715347/dataTableExamples.R</a>>
<br>> Probably should have stayed in bed today the way things are going.
<br>>
<br>> A cut and paste from RStudio
<br>> # Data Table exercises
<br>> require(data.table)
<br>> a <- seq(2L,40L, by = 4L)
<br>> b <- seq(15L,105L,by = 10L)
<br>> c <- 1:10L
<br>> d <- rep(c(100L,150L),5L)
<br>> e <- 101:110L
<br>> dt <- data.table(a,b,c,d,e)
<br>> dt
<br>> dta <- subset(dt, a < 35)
<br>> dtb <- subset(dta, b > 35)
<br>> dtb
<br>> dtb[, lapply(.SD,median), by = d]
<br>> # Now attempt to subset the rows in i
<br>> vec <- c(a<35, b>35)
<br>> dtvec <- dt[vec, lapply(.SD, median, na.rm = TRUE), by = d]
<br>> dtvec
<br>>
<br>> And console output
<br>>> # Now attempt to subset the rows in i
<br>>> vec <- c(a<35, b>35)
<br>>> dtvec <- dt[vec, lapply(.SD, median, na.rm = TRUE), by = d]
<br>> Error in `[.data.table`(dt, vec, lapply(.SD, median, na.rm = TRUE), by = d)
<br>> :
<br>> Column 1 of result for group 2 is type 'double' but expecting type
<br>> 'integer'. Column types must be consistent for each group.
<br>>> dtvec
<br>> a b c d e
<br>> 1: 2 15 1 100 101
<br>> 2: 6 25 2 150 102
<br>> 3: 10 35 3 100 103
<br>> 4: 14 45 4 150 104
<br>> 5: 18 55 5 100 105
<br>> 6: 22 65 6 150 106
<br>> 7: 26 75 7 100 107
<br>> 8: 30 85 8 150 108
<br>> 9: 34 95 9 100 109
<br>> 10: NA NA NA NA NA
<br>> 11: NA NA NA NA NA
<br>> 12: NA NA NA NA NA
<br>> 13: NA NA NA NA NA
<br>> 14: NA NA NA NA NA
<br>> 15: NA NA NA NA NA
<br>> 16: NA NA NA NA NA
<br>>
<br>> The error message has me confused.
<br>> /Column 1 of result for group 2 is type/
<br>> What group 2? I have only grouped on column "d". Result 1 is ???? No idea
<br>> what "result 1" is referring to, is it the subset in "i", the median of col
<br>> a?? No clue.
<br>>
<br>> I have only created integer variable for the data table, so why the
<br>> rejection " Column 1 of result for group 2 is type 'double' but expecting
<br>> type 'integer'. Column types must be consistent for each group." What
<br>> double? I have not created any double numbers.
<br>>
<br>> Carl Sutton
<br>>
<br>>
<br>>
<br>> -----
<br>> Carl Sutton
<br>> --
<br>> View this message in context: <a href="http://r.789695.n4.nabble.com/subset-data-table-in-i-with-multiple-criteria-for-multiple-variables-tp4715347.html" target="_blank" rel="nofollow" link="external">http://r.789695.n4.nabble.com/subset-data-table-in-i-with-multiple-criteria-for-multiple-variables-tp4715347.html</a><br>> Sent from the datatable-help mailing list archive at Nabble.com.
<br>> _______________________________________________
<br>> datatable-help mailing list
<br>> <a href="" rel="nofollow" target="_top" link="external">[hidden email]</a>
<br>> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank" rel="nofollow" link="external">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a></div></div>_______________________________________________
<br>datatable-help mailing list
<br><a href="" rel="nofollow" target="_top" link="external">[hidden email]</a>
<br><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank" rel="nofollow" link="external">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
<br>
<br>
<hr color="#cccccc" noshade='size="1"'>
<div style="font: 12px/normal tahoma, geneva, helvetica, arial, sans-serif; color: rgb(68, 68, 68); font-size-adjust: none; font-stretch: normal;">
<div style="font-weight: bold;">If you reply to this email, your message will be added to the discussion below:</div>
<a href="http://r.789695.n4.nabble.com/subset-data-table-in-i-with-multiple-criteria-for-multiple-variables-tp4715347p4715360.html" target="_blank" rel="nofollow" link="external">http://r.789695.n4.nabble.com/subset-data-table-in-i-with-multiple-criteria-for-multiple-variables-tp4715347p4715360.html</a>
</div>
<div style="font: 11px/1.5em tahoma, geneva, helvetica, arial, sans-serif; color: rgb(102, 102, 102); margin-top: 0.4em; font-size-adjust: none; font-stretch: normal;">
To unsubscribe from subset data table in i with multiple criteria for multiple variables, <a href="" target="_blank" rel="nofollow" link="external">click here</a>.<br>
<a style="font: 9px/normal serif; font-size-adjust: none; font-stretch: normal;" href="http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" target="_blank" rel="nofollow" link="external">NAML</a>
</div></div><br><br></div> </blockquote> </div> </div> </div></div>
<div class="signature" style="margin-top:1em;color:#666666;font-size:11px;">
Carl Sutton
</div>
<br/><hr align="left" width="300" />
View this message in context: <a href="http://r.789695.n4.nabble.com/subset-data-table-in-i-with-multiple-criteria-for-multiple-variables-tp4715347p4715361.html">Re: subset data table in i with multiple criteria for multiple variables</a><br/>
Sent from the <a href="http://r.789695.n4.nabble.com/datatable-help-f2315188.html">datatable-help mailing list archive</a> at Nabble.com.<br/>