Tutorial by Examples

# example data DT = as.data.table(mtcars, keep.rownames = TRUE) To rename a column (while keeping its data the same), there is no need to copy the data to a column with a new name and delete the old one. Instead, we can use setnames(DT, "mpg_sq", "mpq_squared") to modify ...
# example data DT = data.table(iris) To modify factor levels by reference, use setattr: setattr(DT$Species, "levels", c("set", "ver", "vir") # or DT[, setattr(Species, "levels", c("set", "ver", "vir"))] The sec...
# example data set.seed(1) n = 1e7 ng = 1e4 DT = data.table( g1 = sample(ng, n, replace=TRUE), g2 = sample(ng, n, replace=TRUE), v = rnorm(n) ) Matching on one column After the first run of a subsetting operation with == or %in%... system.time( DT[ g1 %in% 1:100] )...
Consider a grid working on some task, e.g. a parallel reduction. Initially, each block can do its work independently, producing some partial result. At the end however, the partial results need to be combined and merged together. A typical example is a reduction algorithm on a big data. A typica...
Consider an array of work items. The time needed for an each work item to complete varies greatly. In order to balance the work distribution between blocks it may be prudent for each block to fetch the next item only when previous one is complete. This is in contrast to a-priori assigning items to...
Tuples support the following build-in functions Comparison If elements are of the same type, python performs the comparison and returns the result. If elements are different types, it checks whether they are numbers. If numbers, perform comparison. If either element is a number, then the other...
Introduction The PHPUnit Manual describes mocking as such: The practice of replacing an object with a test double that verifies expectations, for instance asserting that a method has been called, is referred to as mocking. So instead of stubbing out code, an observer is created that not onl...
// application/controllers/Company_controller.php <?php if(!defined('BASEPATH')) exit('No direct script access allowed'); class Company_controller extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('companies_mo...
If a void* value is converted to a pointer to object type, T*, but is not properly aligned for T, the resulting pointer value is unspecified. Example: // Suppose that alignof(int) is 4 int x = 42; void* p1 = &x; // Do some pointer arithmetic... void* p2 = static_cast<char*>(p1) + 2; ...
To start GDB, in the terminal, gdb <executable name> For the above example with a program named main, the command becomes gdb main Setting Breakpoints You'll probably want you program to stop at some point so that you can review the condition of your program. The line at which you wan...
Batch file command line arguments are parameter values submitted when starting the batch. They should be enclosed in quotes if they contain spaces. In a running batch file, the arguments are used for various purposes, i.e. redirection to :labels, setting variables, or running commands. The argument...
When more than 9 arguments are supplied, the shift [/n] command can be used, where /n means start at the nth argument, n is between zero and eight. Looping through arguments: :args set /a "i+=1" set arg!i!=%~1 call echo arg!i! = %%arg!i!%% shift goto :args Note, in the above exam...
Bottom sheets slide up from the bottom of the screen to reveal more content. They were added to the Android Support Library in v25.1.0 version and supports above all the versions. Make sure the following dependency is added to your app's build.gradle file under dependencies: compile 'com.android...
Assuming you have Eclipse IDE for Java Developers installed, start Eclipse, click "Help" -> "Install New Software..." Select "--All Available Sites--" at "Work with:", and navigate to "Eclipse Plugin Development Tools". Select "Eclipse Pl...
Automatic Linebreaks Table content is line wrapped automatically if it is too wide. In the following example, text is added to the second column, which causes oth the text itself and the column header of the first column to be wrapped. | this is a really wide column header | another header | | -...
io-streams is Stream-based library that focuses on the Stream abstraction but for IO. It exposes two types: InputStream: a read-only smart handle OutputStream: a write-only smart handle We can create a stream with makeInputStream :: IO (Maybe a) -> IO (InputStream a). Reading from ...
Let's create an Enumerator for Fibonacci numbers. fibonacci = Enumerator.new do |yielder| a = b = 1 loop do yielder << a a, b = b, a + b end end We can now use any Enumerable method with fibonacci: fibonacci.take 10 # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
If an iteration method such as each is called without a block, an Enumerator should be returned. This can be done using the enum_for method: def each return enum_for :each unless block_given? yield :x yield :y yield :z end This enables the programmer to compose Enumerable operati...
Use rewind to restart the enumerator. ℕ = Enumerator.new do |yielder| x = 0 loop do yielder << x x += 1 end end ℕ.next # => 0 ℕ.next # => 1 ℕ.next # => 2 ℕ.rewind ℕ.next # => 0
When multiple variables are defined at the beginning of the batch, a short definition form may be used by employing a replacement string. @echo off set "vars=_A=good,_B=,_E=bad,_F=,_G=ugly,_C=,_H=,_I=,_J=,_K=,_L=,_D=6 set "%vars:,=" & set "%" for /f %%l in ('set _'...

Page 682 of 1336