Tutorial by Examples: f

One might want to group their data by the runs of a variable and perform some sort of analysis. Consider the following simple dataset: (dat <- data.frame(x = c(1, 1, 2, 2, 2, 1), y = 1:6)) # x y # 1 1 1 # 2 1 2 # 3 2 3 # 4 2 4 # 5 2 5 # 6 1 6 The variable x has three runs: a run of l...
Given this setup code: var dict = new Dictionary<int, string>() { { 1, "First" }, { 2, "Second" }, { 3, "Third" } }; You may want to read the value for the entry with key 1. If key doesn't exist getting a value will throw KeyNotFoundException,...
Shift Use .shift to remove the first item of an array. For example: var array = [1, 2, 3, 4]; array.shift(); array results in: [2, 3, 4] Pop Further .pop is used to remove the last item from an array. For example: var array = [1, 2, 3]; array.pop(); array results in: [1, 2] Bot...
function Invoke-MyCmdlet { [CmdletBinding(SupportsShouldProcess = $true)] param() # ... }
5.0 In PowerShell 5.0+ you can list available constructors by calling the static new-method without parentheses. PS> [DateTime]::new OverloadDefinitions ------------------- datetime new(long ticks) datetime new(long ticks, System.DateTimeKind kind) datetime new(int year, int month, int d...
MATLAB code can be saved in m-files to be reused. m-files have the .m extension which is automatically associated with MATLAB. An m-file can contain either a script or functions. Scripts Scripts are simply program files that execute a series of MATLAB commands in a predefined order. Scripts do no...
You can declare properties in interfaces. Since an interface cannot have state you can only declare a property as abstract or by providing default implementation for the accessors. interface MyInterface { val property: Int // abstract val propertyWithImplementation: String g...
Reading a file line by line public class Main { public static void main(String[] args) { try { Scanner scanner = new Scanner(new File("example.txt")); while(scanner.hasNextLine()) { String line = scanner.nextLine(); ...
The data.table package provides a convenient way to group by runs in data. Consider the following example data: library(data.table) (DT <- data.table(x = c(1, 1, 2, 2, 2, 1), y = 1:6)) # x y # 1: 1 1 # 2: 1 2 # 3: 2 3 # 4: 2 4 # 5: 2 5 # 6: 1 6 The variable x has three runs: a run ...
DT[where, select|update|do, by] syntax is used to work with columns of a data.table. The "where" part is the i argument The "select|update|do" part is the j argument These two arguments are usually passed by position instead of by name. Our example data below is mtcars =...
<PROJECT_ROOT>\app\build.gradle is specific for app module. <PROJECT_ROOT>\build.gradle is a "Top-level build file" where you can add configuration options common to all sub-projects/modules. If you use another module in your project, as a local library you would have another...
A string representation of a Guid can be obtained by using the built in ToString method string myGuidString = myGuid.ToString(); Depending on your needs you can also format the Guid, by adding a format type argument to the ToString call. var guid = new Guid("7febf16f-651b-43b0-a5e3-0da8da4...
Key Value Coding is integrated into NSObject using NSKeyValueCoding protocol. What this means? It means that any id object is capable of calling valueForKey method and its various variants like valueForKeyPath etc. ' It also means that any id object can invoke setValue method and its various vari...

for

Syntax: for (initializer; condition; iterator) The for loop is commonly used when the number of iterations is known. The statements in the initializer section run only once, before you enter the loop. The condition section contains a boolean expression that's evaluated at the end of every loop ...
A std::vector automatically increases its capacity upon insertion as needed, but it never reduces its capacity after element removal. // Initialize a vector with 100 elements std::vector<int> v(100); // The vector's capacity is always at least as large as its size auto const old_capacity...
To format Dates we use the format(date, format="%Y-%m-%d") function with either the POSIXct (given from as.POSIXct()) or POSIXlt (given from as.POSIXlt()) d = as.Date("2016-07-21") # Current Date Time Stamp format(d,"%a") # Abbreviated Weekday ## [1] &qu...
# test date-time object options(digits.secs = 3) d = as.POSIXct("2016-08-30 14:18:30.58", tz = "UTC") format(d,"%S") # 00-61 Second as integer ## [1] "30" format(d,"%OS") # 00-60.99… Second as fractional ## [1] "30.579" for...
To start coding in the first place, you have to right click your VBA Project in the left list and add a new Module. Your first Hello-World Code could look like this: Sub HelloWorld() MsgBox "Hello, World!" End Sub To test it, hit the Play-Button in your Toolbar or simply hit the...
To do an insert on specific columns (as opposed to all of them) you must specify the columns you want to update. INSERT INTO USERS (FIRST_NAME, LAST_NAME) VALUES ('Stephen', 'Jiang'); This will only work if the columns that you did not list are nullable, identity, timestamp data type or compute...
To insert multiple rows of data in SQL Server 2008 or later: INSERT INTO USERS VALUES (2, 'Michael', 'Blythe'), (3, 'Linda', 'Mitchell'), (4, 'Jillian', 'Carson'), (5, 'Garrett', 'Vargas'); To insert multiple rows of data in earlier versions of SQL Server, use "UNION ALL" like so: ...

Page 46 of 457