Get startedGet started for free

Advanced computations in j

1. Advanced computations in j

In this lesson, you will see how you can perform multiple computations in "j".

2. Compute in j and return a data.table

Remember you can select and rename multiple columns using dot parentheses? You can use this approach to perform computations too. As an example, here we compute the mean and median of duration column. You can perform any computation you would like on any number of columns using this approach within the dot parentheses.

3. Question

If you are curious, try and figure out how you would perform this computation using the data frame way. How do you find that approach? Is your code straightforward and clear?

4. Combining with i

Even when you have multiple computations or selections, you can combine it with "i" the same way as before. data table will restrict the computation or selection to only those rows filtered in "i". Remember, "j" operates on the rows after "i" is processed. In order to compute the mean and median of trips that start from "Japantown", you can simply provide the expression to filter those rows in "i" and then compute the mean and median of duration in "j", as shown here.

5. Question

Once again, think about how you'd go about accomplishing this task with a data frame! Being able to manipulate on the rows and columns within the square brackets, makes the code much more clearer, straightforward and efficient. It also results in much less typing.

6. Let's practice!

It's your turn to practice multiple computations the data table way.