1,411 karma · joined March 31, 2013
Here's some completely not-the-point of the article code review since I can't help myself. If you can set up earlier steps give you a named list for `col_grouping`, and use `lapply`, the code is a little more concise:
efficient_flow_agg <- function(dat, col_grouping, gpcol_name="GroupMembership") {
make_postproc <- function(gp, groups) {
gp$preproc(dat[gp$which_cols]) |>
lapply(collapse::BY, groups, gp$aggfun) |>
gp$postproc()
}
col_grouping |>
lapply(make_postproc, groups = dat[[gpcol_name]]) |>
as.data.frame()
}
* I had previously written here that `tapply` is probably faster, but apparently `tapply` does exactly `unlist(lapply(split(x, g), f)))` anyway? wtf R. Strange there's not something like `collapse::BY` in base R.Personally I'll happily take not being able to use those as column names if it means I can avoid always typing : before every in-data variable, but your comment gave me a better understanding of why it would be bad for some other person or scenario, perhaps where short term ease-of-use is lower on the list of priorities.
For your second example, it doesn't come up in R because a data frame column cannot be a function. Columns must be vectors (including lists) and you could have a vector where one or all elements are functions, but the column itself cannot not be a function (functions are not vectors), so there's no ambiguity there. To call a function stored in your data frame you'd have to access an element of the column, and any access method, e.g. `[[` or `$` would make the resulting set of characters invalid as the name of an object (without backticks, which would then disambiguate the intent)
df <- tibble(x = list(function(x) x + 1))
df %>%
mutate(y = x[[1]](3))
Separate from dplyr, in R when you use `(` to call a function it searches only for functions by that name. log <- 3
log(1)
# 0
frog <- 3
frog(3)
# Error in frog(3) : could not find function "frog"
log <- function(x) x^2
log(1)
# 1 mutate(df, b = .env$a + 1)
And if you have a string (contained in a_var) which identifies a variable you can do mutate(df, b = .data[[a_var]] + 1)
You could argue these feel clumsy, but I wouldn’t say it’s “hard” to do either of these things with dplyr.There are many chess AIs on chess.com specifically designed to play "like" a specific grandmaster or well known chess streamer. I don't think any titled player would not be able to guess they're playing a computer if they played a few games against the AI without being told. It's very well known that computer moves are very different from human moves, even the ones specifically designed to represent a human.
So this isn’t actually any cheaper than what I would think of as the standard solution, which is to buy A drawing tablet (which also conveniently doesn’t take up a ton of space in your living area)
Name brand (Wacom) drawing tablet for $60:
https://smile.amazon.com/dp/B07S1RR3FR/ref=cm_sw_r_cp_api_gl...
Here's the calculation used in main.js line 77 applied to a very extreme unrealistic example. I simulated 253 days of return percentages from a uniform distribution between -5.5% and 5.6%, and then the actual total return percent, calculated in R
set.seed(2020)
n <- 253
daily_gain <- runif(n, -.055, .056)
total_gain <- sum(daily_gain)
avg <- total_gain/n
annualizedReturn <- (1 + avg)^n -1
annualizedReturn
# [1] 0.2933685
prod(1 + daily_gain) - 1
# [1] 0.1324846
Edit:In reality the actual numbers are likely to be not nearly as different as this example. I chose uniformly distributed returns with a wide range to make the reason against this calculation very obvious. Here's an example return distribution where there's hardly any difference. Normal returns with average of 0.085% and standard deviation of .05 i.e. daily_gain <- rnorm(n, .085/100, .05/100) gives
annualizedReturn
# 1] 0.2414539
prod(1 + daily_gain) - 1
# [1] 0.2414051
For good measure here's one in the middle where your returns are normally distributed with an average of 0.35% and a sd of .2%, but then you have on average 10 bad days a year where returns are 5 percentage points lower than that distribution i.e. daily_gain <- rnorm(n, .35/100, .2/100) - rbinom(n, 1, 10/n)*.05 gives annualizedReturn
# [1] 0.2712024
prod(1 + daily_gain) - 1
# [1] 0.2490317Quotes from the article:
> Rich people pretend to be poor to fit in
> They want independence from their parents
[1] Except #2. A large percentage of people drop out of PhD programs in America.