datamentor.io/r-programming seems to be a good place for R information.
Note, this is about R, the programming language, not RStudio, the software that uses R to do data analysis.
The Tuturial on this page s what we are going to focus on below.
That Tutorial link highlighted in the right actually just redirects to the bottom of the same page...
STEPS to HELP yourself...
Step 1) Go to https://www.datamentor.io/r-programming/ and click on R Tutorials Link identified above..
If nothing has changed, you should end up here...
https://www.datamentor.io/r-programming/#tutorial
(note, it's the same link with an anchor added which caused the page to scroll down)
Step 2) Click on the first option under R Introduction which is "R Reserved Words"
If nothing has changed, you should end up here...
Step 3) Creating a bookmark for this page ( https://www.datamentor.io/r-programming/reserved-words/ ). This gets you quickly to the top of their tutorial with the telescoping menu for all help items by topic on the right quickly
Step 4) Skim the entire R Tutorial Section at datamentor.io starting with link above and going through each of those sections and section items in the menu on the right.
Generally speaking the best way to program is to use the concepts that are common to most/all programming languages and try to avoid the shortcuts any given language offers as they require more attention then they are worth.
This will make a lot more sense as you start scaling up in languages you use. Stick to the basics. Obviously, if this is your first language you don't know what is common and what is a R specfiic shortcut. I'll try to point those out as we go.
This tutorial offerred by DataMentorl is great to get going.
Here we go in full speed. I'm going to go to the top of the tutorial, I'm going to read each item myself and make notes for myself (and a few others who my find this)
When you get there, look at the menu on the right ^^^ >>>>
These notes below (vvvv) are from my skimming of each item in that menu >>>>> on 10/2/2019.
Reserved Words -- very standard and not many. if, else, for, in, next while, break, repeat, function, TRUE, FALSE, NULL, inf, NaN, NA, NA_integer_, NA_real, NA_complex, NA_character . List can be reviewed from console prompt with help(reserved) or ?reserved. R is CASE SENSITIVE
Variables and Constants -- identifiers can contain "." or "u" or aphanumeric. Must start with alpha or " . ". Apperently, originally this language allowed for periods and not underscores in variable names. A very odd thing indeed. They suggest using that or camelCase, I strongly disagree. Using periods in variable names is horrific give the use of object oriented programming in which periods stand for something far different. Use underscores or camelCase only. the do have a month.name and a month.abb built in.
Operators -- Generally teh same as java script. I'm not familiar with the single bang option ( I ) or the single & . Need to check on those
Precedence and Associative - In addition to > < = / * there are quite a few others. I'd try not to use their alternative symbols for associating values like <- too much or at all. Keep it as simple as possible. You may need this page if you come across code from others who thought all these options were worth using...
If else -- Identical syntax to java script if ( ) { blah }
for - for (index in range of values) { blah }
while - while (test_expression) { blah }
break and next -- break breaks out of a loop. next skips that iteration and continues looping (I believe this is 'continue' in javascript)
repeat loop -- repeat {blah} >> Must use the break to exit. I've not used this one before. All that can be done with this should be able to be done with the others above I think...
function -- func_name = function (params) { } , Call a function with () after function name. They have a named arguments thingy. I'd avoid if at all possible. Should be no need for it. Set default values inside the functions not this way in the function initialization
function return value -- return ( something) . This system has a strange system of returning the last calculation by default if nothing is specified. That can lead to bad outcomes, thus explicitily define returns and be careful of this "nicety" that can only really cause trouble. Multiple returns can be returned in an array, but also in a "list" and a data.block as we saw in session 2. Learning this formatting on returns may be very relevant for this platform.
Environment and Scope -- The "Global Environment" is where things are stored by default. Can be referred to as .GlovvalEnv in R. Can use ls() to show what vars and funs are currently defined (or just use the window in rStudio). environment() gets full environment. Local variables are those defined within functions. To assign a value to a global variable while in a local function you must use <<- . That is key. if no global exists it will create one. I like using global variables instead of passing a lot of things around, but you need to be very cognizant of how they work and what you are doing. And you need to keep track of them carefully. Some folks do NOT like this approach like I do.
Recursive Function -- A recursive function is one that calls itself. Super powerful but can fubar and get confusing. If you want to show contents of all subfolders for a given folder and their subfolders, without specifying exactly how many folders are anywhere, you'd use a recursive function.
R Infix Operator -- Interesting read. a+b is in fact calling a function that is the sum function with a and b a paramaters +(a,b) . Seems you can make your own of these too.. Don't go here unless you need to
Switch Function -- A switch function is also a "case statement" or a case function. It can be thought of as another way to write a bunch of If/then statements that is cleaner when you get a bunch of those together. switch(exrpression, list of options) . Their examples are confusing.
Vectors - they call an array a vector. Don't know any other way to state that. The also start this out with a strange leading c for some reason. c ( x, y). The semicolon is used to create vectors of consecutive numbers and when it is uses, the c() is not required it doesnt seem... arrX = c(1,5,7) arrX = 1:7 . I'd highly suggest using arr to preface any "vectors" for a variable naming convention. Their name of vectors with a single x can/will get brutally confusing as you get more complex. You can also create a vector with a seq() function . seq(1, 3, by =0.2) Ahh. there it is. Was wondering about that. Im not sure why this isn't just the c function with a 3rd parameter, but oh well. Accessing array (vector) values arrX[3] gets third value. Note this is 1 based not 0 based. arrX[c(2,4)] for positions 2 and 4. That is not common in other languages I don't think. I'd be getting those individually and putting them in a new c . so arrY = c(arrX[2], arrX[4] ) arrX[-1] gets full array less item 1. There is a short cut for logical vectoring. I'd use a loop to test it. Using character vector as object. This is comparable to a javascript object. I'd label as obj instead of arr objX = c("first"=3 , "second"=0, "third"=9 ) objX["second"] returns second, 0 (it returns both the label and the value). There is info here on modifying (arrX[5]= "new value" ) and deleting vectors (write over or set to NULL) too. This vectors section really crosses up arrays with other types of variables as compared to other languages...
Matrix - 2 dim structure (aka a 2 dimensional array) matrix(1:9, nrow = 3, ncol = 3) colnames() and colrows() can be used to change names... can use cbind and rbind to create matrix too. Can also use dim() command.
List - This is basically yet another way to create a data object from a javascript perspective. objX = list("a" = 2.5, "b" = TRUE, "c" = 1:3) Access list components with objX$a which is same as objX[["a"}} . to modify or ad list item use objX[["a"}} = new value (may need to use <-) . To delete list value write over it or set to NULL.
Data.Frame - This outputs items in an array/matrix form... We saw this example in a prior session data.fram( "SN = 1:2, "Age" = c(21,15), "Name" = c("John", "Dora") , stringAsFactors { WHAT?) see their exampoe for the string as factors. I think it just avoids it from trying to say all the data types are the same... Data input functions like read.table(), read .csv(), read, delim(), read.fwf() read data into a dataframe by default. To access, can use [, [[, or $ . Use rbind or cbind to add stuff
Factor- What a strange overly complex thing this is. It's just an array used like a select list with a limited number of items. It's a freaking array folks. the options are called "levels()". check if something is a factor with teh class() function... (this is getting dumb)
S3 and S4 - Again, way too much vocabulary for a f--ing object which is just an array with name value pairs. Focus on S4 here if you have to. setClass("student", slots=list(name="character", age="numeric, GPA="numeric")). Try to just use your own array and such whenever possible... A comma separated value list of items is all that is needed with another that defined the labels or row data. (my suggestion whenever possible) studentsColHeaders = ["name", "age", "eye color"] . student[i]= [ "bob", 32, "brown"] with data controls on the data entry...
Inheritance = using an existing class (list of fields nad fiedl structure) to create a new class (with the same fields nad field structure plus some)
Programming Bar Plot -- arrMaxTemp = c(22, 25, 26) barplot(arrMaxTemp) . With added parameters barbplot(arrMaxTemp, main = "Max Temp in a week", xlab = "Degree Cel", ylab = "Day", arrNames = c("Sun", "Mon", "Tues"), color = "darkred", horiz = TRUE). other good examples on the page
Programming Histogram -- hist() see examples
Programming Pie - pie() see examples
Programming Box Plot - boxplot()
Programming Strip Chart - stripchart()
R Advanced Topics
Plot function -- plot() -- for data and lines and such
Programming subplot -- For putting multiple graphs on a single chart... part() == the name does not seemingly match the functionality...
Saving Plot -- Save as bitmap,jpg, png, vector image, tiff, pdf
Color -- Color names
3d - 3d plots..