« first day (1251 days earlier)      last day (2040 days later) » 

6:25 AM
Good morning all
 
6:43 AM
hello hello :-)
 
7:23 AM
Ciao tutti frutti.
 
7:56 AM
aloha!
 
 
1 hour later…
9:00 AM
only way I see : wh_v1 <- my_data_table[, V1]==V1; my_data_table[wh_v1]
 
@Jaap seems more "too broad" to me
 
that too
 
they should also have 'too bored'
2
 
30 messages moved to Trash can
 
10:07 AM
Hello
 
10:36 AM
 
10:53 AM
@zx8754 yes
 
@Jaap done, is this how you wanted?
 
seems fine to me
 
 
1 hour later…
11:59 AM
Is there a way to keep tracks of results names when working with by in a data.table and applying the function on multiple columns?
e.g:
dumdt <- data.table(P1=rnorm(10), P2=rnorm(10), Gpe=sample(c("A", "B"), 10, replace=TRUE))
dumdt[, lapply(.SD, function(pat) as.list(summary(pat))), by=Gpe, .SDcols=c("P1", "P2")]
    Gpe          P1         P2
 1:   B   -1.253818 -0.1355741
 2:   B  -0.3265063 -0.0252563
 3:   B   0.2227803 0.02019383
 4:   B -0.07329352  0.1134442
 5:   B    0.475993  0.1588944
 6:   B   0.5150836  0.5489634
 7:   A   -1.113862 -0.8611694
 8:   A  -0.7804085 -0.5305966
 9:   A  -0.7141381  0.3000519
10:   A  -0.5284982   0.128357
but with just one column it's ok:
dumdt[, as.list(summary(P1)), by=Gpe]
   Gpe      Min.    1st Qu.     Median        Mean    3rd Qu.      Max.
1:   B -1.253818 -0.3265063  0.2227803 -0.07329352  0.4759930 0.5150836
2:   A -1.113862 -0.7804085 -0.7141381 -0.52849824 -0.5916422 0.7244576
adding a column specifying "which result" it is could be nice (like first column "Gpe", second column, "names" (or "V1" or "attr"...) with results labels, here "Min.", "1st Qu.", etc.
 
@Cath In that case you can first make it extra long, then by and summarise
 
12:14 PM
@Axeman hmm? (sorry, I don't get it :-/)
 
in tidyverse: dumdt %>% gather(var, val, -Gpe) %>% group_by(var, Gpe) %>% summarise(....
 
@Axeman nope no tidyverse ;-)
 
@Cath yeah i know, but you can do equivalent, i.e melt(?), then have both var and Gpe in your by
then you get nrow = n_groups * n_variables
dumdt2 <- melt(dumdt)
dumdt2[, as.list(summary(value)), by=c('Gpe', 'variable')]
 
12:37 PM
@Axeman thanks, I'll try ! for now, I can only get one column with variable names per "treated" columns... :
   Gpe      V1          V2      V3          V4
 1:   B    Min. -1.25381833    Min. -0.13557413
 2:   B 1st Qu. -0.32650625 1st Qu. -0.02525630
 3:   B  Median  0.22278030  Median  0.02019383
 4:   B    Mean -0.07329352    Mean  0.11344424
 5:   B 3rd Qu.  0.47599302 3rd Qu.  0.15889437
 6:   B    Max.  0.51508364    Max.  0.54896343
 7:   A    Min. -1.11386203    Min. -0.86116945
 8:   A 1st Qu. -0.78040847 1st Qu. -0.53059661
 9:   A  Median -0.71413812  Median  0.30005195
10:   A    Mean -0.52849824    Mean  0.12835697
 
my code gives this instead:
   Gpe variable       Min.    1st Qu.     Median        Mean   3rd Qu.      Max.
1:   A       P1 -1.2958826  0.1775047  0.3964525  0.51765167 1.1746217 1.8187391
2:   B       P1 -0.4523218 -0.3522874 -0.2522531  0.04516207 0.2939040 0.8400611
3:   A       P2 -1.3025704 -1.1653844 -0.9409274 -0.29870719 0.7443288 0.9946587
4:   B       P2 -1.3090981 -0.7244504 -0.1398027 -0.01780298 0.6278446 1.3954919
 
@Axeman way better, though not totally perfect ;-) (best would be P1, P2 as columns), I'll play around with your sol. Re-thanks ! :-)
 
@Cath Just re-melt that...?
 
 
1:41 PM
exact same answer as other answers but with less explanations and posted 9 min later... (and poster just put a "lol" comment on the other answer) <sigh>
 
@Cath And the first answer spreads confusion
 
@Axeman indeed it's not very well termed!
I guess OP meant "does not create a list where each item is also a list" or something like that...
 
2:15 PM
 
2:34 PM
@Cath one more delete vote needed
@Cath maybe this: melt(dumdt, id = "Gpe")[, as.list(summary(value)), by = .(Gpe, variable)][, dcast(melt(.SD, id = 1:2), Gpe + variable.1 ~ variable)] ?
result:
    Gpe variable.1          P1          P2
 1:   A       Min. -1.16554485 -3.22732283
 2:   A    1st Qu. -0.63385561 -1.13354389
 3:   A     Median -0.27538908 -0.45983237
 4:   A       Mean -0.44677384 -0.70699711
 5:   A    3rd Qu. -0.16301151  0.16732930
 6:   A       Max. -0.08542326  0.88673615
 7:   B       Min. -1.08569914 -0.77179177
 8:   B    1st Qu. -0.88531158 -0.30649491
 9:   B     Median -0.80144897 -0.14040333
10:   B       Mean -0.40449663 -0.09191559
11:   B    3rd Qu. -0.32063403  0.07417600
 
@Jaap nice, exactly what I'm after !! :-)
 
:-)
 
2:49 PM
@Cath If that solved your problem please accept by visiting @Jaap's amazon wish list :D
3
I actually saw a profile in SO once where the guy had a link to his wishlist. He was also a high rep user
 
haha, I like your idea @Sotos :-P
 
@Sotos excellent :-)
 
@Sotos or just upvote some random post(s).
 
@Jaap hehehe...you never know..someone might actually buy you something
 
you never know indeed; but imo it is also contradictory to the spirit of contributing to SO
 
2:55 PM
@Jaap Agreed.
 
 
1 hour later…
3:57 PM
@Uwe the other way around happens to me regularly ;-)
 
4:23 PM
my code golf: dumdt[, c(lapply(.SD, function(x) s <<- summary(x)), .(stat = names(s))), by=Gpe]; rm(s) (for same-ish result)
or with more unreadable parentheses: dumdt[, c(.(stat = names(first(s <- lapply(.SD, summary)))), s), by=Gpe]
nice verbose message printed for the code above: "Column 2 of j is a named vector (each item down the rows is named, somehow). Please remove those names for efficiency (to save creating them over and over for each group). They are ignored anyway."
 
5:17 PM
glad to see reprex is still going community.rstudio.com/t/… last major event i recall was it being taken off CRAN
 
 
1 hour later…
6:19 PM
a couple R and python books in a bundle over here: humblebundle.com/books/learn-you-some-code-books
pretty sure i went through all of "Automate the Boring Stuff with Python" in free online form, though
 
7:17 PM
Correct me if I'm wrong:
The first link is about how to collapse a list of lists. It is thus a correct duplicate imo. — Jaap 4 mins ago
 
7:34 PM
@Jaap you're right enough :) op has singletons in most fields, but multiple values in 4, 5, 6 and so needs recycling, as they say
but otherwise, it's the same
if they really care about efficiency, they'll make two tables (one with order + core data cols 4-6; another with order + order metadata in other cols)
 

« first day (1251 days earlier)      last day (2040 days later) »