Tutorial by Examples: c

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...
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." } ...
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...
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...
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...
To share your code you create a repository on a remote server to which you will copy your local repository. To minimize the use of space on the remote server you create a bare repository: one which has only the .git objects and doesn't create a working copy in the filesystem. As a bonus you set thi...
If there are sections of code that you are considering removing or want to temporarily disable, you can comment it out with a block comment. /* Block comment around whole function to keep it from getting used. * What's even the purpose of this function? int myUnusedFunction(void) { int i =...
Let's say we have the following structure: struct MY_STRUCT { int my_int; float my_float; }; We can define MY_STRUCT to omit the struct keyword so we don't have to type struct MY_STRUCT each time we use it. This, however, is optional. typedef struct MY_STRUCT MY_STRUCT; If we th...
If MsgBox("Click OK") = vbOK Then can be used in place of If MsgBox("Click OK") = 1 Then in order to improve readability. Use Object Browser to find available VB constants. View → Object Browser or F2 from VB Editor. Enter class to search View members available ...
Descriptive names and structure in your code help make comments unnecessary Dim ductWidth As Double Dim ductHeight As Double Dim ductArea As Double ductArea = ductWidth * ductHeight is better than Dim a, w, h a = w * h This is especially helpful when you are copying data from one ...
Let's define a function of 2 arguments: def add: (Int, Int) => Int = (x,y) => x + y val three = add(1,2) Currying add transforms it into a function that takes one Int and returns a function (from one Int to an Int) val addCurried: (Int) => (Int => Int) = add2.curried // ...
In PHP 5.3+ and above you can utilize late static binding to control which class a static property or method is called from. It was added to overcome the problem inherent with the self:: scope resolutor. Take the following code class Horse { public static function whatToSay() { echo ...

Page 126 of 826