Question: Chromecast session status returns undefined on Chrome mobile ios. The session exists and has other properties defined, like sessionID. On the desktop, the session status returns "connected", "disconnected", or "stopped" as expected. Is this a bug with Chrome ios? Is there another way to detect the session status?

Answer: 
Here's how I'd handle this using `data.table`.

```
require(data.table)
setkey(setDT(df), 
      Month)[.(mon = 1:3),                          ## i
      NewSize := Size * get(paste0("Month", mon)),  ## j
      by=.EACHI]                                    ## by

```

* `setDT` converts `df` from *data.frame* to *data.table* by reference.
* `setkey` reorders that *data.table* by the column specified, `Month`, in increasing order, and marks that column as *key* column, on which we'll perform a join.
* We perform a join on the key column set in the previous set with the values `1:3`. This can also be interpreted as a *subset* operation that extracts all rows matching `1,2 and 3` from the key column `Month`.
* So, for each value of `1:3`, we calculate the matching rows in `i`. And on those matching rows, we compute `NewSize` by extracting `Size` and `MonthX` for those matching rows, and multiplying them. We use `get()` to achieve extracting the right `MonthX` column.
* `by=.EACHI` as the name implies, executes the expression in `j` for each `i`. As an example, `i=1` matches (or joins) to rows 1:3 of `df`. For those rows, the j-expression extracts `Size = 30,20,10` and `Month1 = 1.0, 0.2, 0.0`, and it gets evaluated to return `30, 4, 0`. And then for `i=2` and so on..

Hope this helps a bit even if you're looking for a `dplyr` only answer.
You can use `apply`:

```
apply(df, 1, function(u) as.numeric(u[paste0('Month', u['Month'])])*as.numeric(u['Size']))
#[1] 30  4  0  6 20  0  0 50 12

```

Or a vectorized solution:

```
bool = matrix(rep(df$Month, each=3)==rep(1:3, nrow(df)), byrow=T, ncol=3)

df[c('Month1', 'Month2', 'Month3')][bool] * df$Size
#[1] 30  4  0  6 20  0  0 50 12

```