Monday, December 3, 2018

R syntax

1. For assignment, safest to use are: <- and ->.

Printing:
2. Using a variable without assigning will print it.
3. print() prints single expression, show() can print plots,graphs,tables etc
4. cat() can print multiple results.
5. paste() can store the result of resulting string unlike cat() which prints it.
6. result of paste() can be printed by message()
7. message() can also be used like print() but it adds a newline
8. message() won't print list indices etc.

Data types:
1. Numeric - all types of numbers
2. class() function tells the datatype
3. is.numeric() is.integer() will give True/False. is.<datatypename>()
4. append L after the number to make it integer. for e.g. 4L
5. typecasting: val <- as.integer(3+5)
6. An integer is also a numeric. So numeric is like super class of integer.
7. Double is synonym of numeric.
8. Character is the datatype for strings. nchar() is like strlen().
9. For dates: DATE
10. For timestamp: POSIXCT
11. Logical - TRUE/FALSE

Data structures:
1. Vector(Default)/Array/DataFrame/Matrix/List
2. List can have different kind of elements unlike Vector.
3. Vector can have only simple datatypes.
4. Array - only same type elements. Arrays have dimensions.
5. Matrix - is a 2D array - has different functions exclusively for math operations.
6. DataFrame - is like a SQL table
7. 

No comments:

Blog Archive