Tutorial by Examples

Under the hood, a matrix is a special kind of vector with two dimensions. Like a vector, a matrix can only have one data class. You can create matrices using the matrix function as shown below. matrix(data = 1:6, nrow = 2, ncol = 3) ## [,1] [,2] [,3] ## [1,] 1 3 5 ## [2,] 2 4...
Data frames are likely the data structure you will used most in your analyses. A data frame is a special kind of list that stores same-length vectors of different classes. You create data frames using the data.frame function. The example below shows this by combining a numeric and a character vector...
Lists allow users to store multiple elements (like vectors and matrices) under a single object. You can use the list function to create a list: l1 <- list(c(1, 2, 3), c("a", "b", "c")) l1 ## [[1]] ## [1] 1 2 3 ## ## [[2]] ## [1] "a" "b" &q...
With fixed pattern stri_count_fixed("babab", "b") # [1] 3 stri_count_fixed("babab", "ba") # [1] 2 stri_count_fixed("babab", "bab") # [1] 1 Natively: length(gregexpr("b","babab")[[1]]) # [1] 3 length(gregexpr(...
stri_dup("abc",3) # [1] "abcabcabc" A base R solution that does the same would look like this: paste0(rep("abc",3),collapse = "") # [1] "abcabcabc"
You can specify different application IDs or package names for each buildType or productFlavor using the applicationIdSuffix configuration attribute: Example of suffixing the applicationId for each buildType: defaultConfig { applicationId "com.package.android" minSdkVersion 17 ...
To compare strings alphabetically, use localeCompare(). This returns a negative value if the reference string is lexicographically (alphabetically) before the compared string (the parameter), a positive value if it comes afterwards, and a value of 0 if they are equal. var a = "hello"; va...
Detailed instructions on getting stripe-payments set up or installed.
This is an example of a function which returns a string. In the example, the function is called in a statement assigning a value to a variable. The value in this case is the return value of the function. function Get-Greeting{ "Hello World" } # Invoking the function $greeting ...
A function can be defined with parameters using the param block: function Write-Greeting { param( [Parameter(Mandatory,Position=0)] [String]$name, [Parameter(Mandatory,Position=1)] [Int]$age ) "Hello $name, you are $age years old." } ...
Parameters to a function can be marked as mandatory function Get-Greeting{ param ( [Parameter(Mandatory=$true)]$name ) "Hello World $name" } If the function is invoked without a value, the command line will prompt for the value: $greeting = Get-Greeting ...
A compound view is a custom ViewGroup that's treated as a single view by the surrounding program code. Such a ViewGroup can be really useful in DDD-like design, because it can correspond to an aggregate, in this example, a Contact. It can be reused everywhere that contact is displayed. This means t...
This example listens for input coming in over the serial connection, then repeats it back out the same connection. byte incomingBytes; void setup() { Serial.begin(9600); // Opens serial port, sets data rate to 9600 bps. } void loop() { // Send data only when you receive...
Sometimes, we need to update the progress of the computation done by an AsyncTask. This progress could be represented by a string, an integer, etc. To do this, we have to use two functions. First, we need to set the onProgressUpdate function whose parameter type is the same as the second type parame...
If the user authorizes your application, they will be redirected to the following URL: https://[your registered redirect URI]/#access_token=[an access token] &scope=[authorized scopes] Note that the access token is in the URL fragment and not the query string. This means the value w...
Class constants provide a mechanism for holding fixed values in a program. That is, they provide a way of giving a name (and associated compile-time checking) to a value like 3.14 or "Apple". Class constants can only be defined with the const keyword - the define function cannot be used in...
This section provides code and benchmarks for ten unique example implementations which iterate over the entries of a Map<Integer, Integer> and generate the sum of the Integer values. All of the examples have an algorithmic complexity of Θ(n), however, the benchmarks are still useful for provid...
Glide includes two default transformations, fit center and center crop. Fit center: Glide.with(context) .load(yourUrl) .fitCenter() .into(yourView); Fit center performs the same transformation as Android's ScaleType.FIT_CENTER. Center crop: Glide.with(context) .load(yourUr...
The base package parallel allows parallel computation through forking, sockets, and random-number generation. Detect the number of cores present on the localhost: parallel::detectCores(all.tests = FALSE, logical = TRUE) Create a cluster of the cores on the localhost: parallelCluster <- para...
A major problem with parallelization is the used of RNG as seeds. Random numbers by the number are iterated by the number of operations from either the start of the session or the most recent set.seed(). Since parallel processes arise from the same function, it can use the same seed, possibly causin...

Page 203 of 1336