Intro to R programming language from Google Colab
- How to start R on Google Colab?
- How to get R version?
- How to get built-in objects?
- How to get info about any function in R?
- How to show all R options?
- Print and alter the particular option in R
- How to plot a simple function graph in R?
- How to get help on help in R?
- How to get list of R available packages?
- How to list available datasets in R?
- How to get help on any package?
- How to get the list of all R operators?
To start with R programming language I created a small overview of what are the most important things to learn first.
How to start R on Google Colab?
It is possible to run R directly on Google Colaboratory. This means you don’t need to set the environment on your end, just to start and experiment with R.
How to get R version?
There are several ways to get the R version. All these works:
R.Version() R.version R.version.string version
, but my favorite is just
How to get built-in objects?
There is a simple
builtins() command helping to return the names of all R built-in objects. These objects are fetched directly from the symbol table of the R interpreter.
I saw inside the
How to get info about any function in R?
The key is to use the
print prints its argument and returns it invisibly (via invisible(x)). It is a generic function which means that new printing methods can be easily added for new classes.
You can also use
help(print)to get the same results.
Online information about
For me the crucial thing was to use to the idea that every function in R has a package it belongs to. In case of
How to show all R options?
To show all R options you simple type:
options() allow the user to set and examine a variety of global options which affect the way in which R computes and displays its results.
Print and alter the particular option in R
To print a single option you may use
op='width' getOption(op, default = NULL) # same as options(op)
Here is how the
width 80 looks:
And if we alter the width option to 30 the output is different:
How to plot a simple function graph in R?
For the most basic example you will need to have a
seq sequence from
How to get help on help in R?
It may be interesting but
help(help) is also useful.
This will show the full list of
help argument options:
help(topic, package=NULL, lib.loc=NULL, verbose=getOption("verbose"), try.all.packages=getOption("help.try.all.packages"), help_type=getOption("help_type"))
help is interesting because you can
help.search() on any term which is the same as
help.search('abs') # or simple ??abs
How to get list of R available packages?
library() will list all R available packages,
search() will list all loaded packages.
You can load (attach) a package with:
library("dplyr'). Inside a function check if a package has been loaded with
require("dplyr") that returns either
How to list available datasets in R?
data() will list all available datasets.
data loads specified datasets.
Here is the list you may expect:
Data sets in package 'datasets': AirPassengers Monthly Airline Passenger Numbers 1949-1960 BJsales Sales Data with Leading Indicator BJsales.lead (BJsales) Sales Data with Leading Indicator BOD Biochemical Oxygen Demand CO2 Carbon Dioxide Uptake in Grass Plants ChickWeight Weight versus age of chicks on different diets DNase Elisa assay of DNase EuStockMarkets Daily Closing Prices of Major European Stock Indices, 1991-1998 Formaldehyde Determination of Formaldehyde HairEyeColor Hair and Eye Color of Statistics Students Harman23.cor Harman Example 2.3 Harman74.cor Harman Example 7.4 Indometh Pharmacokinetics of Indomethacin InsectSprays Effectiveness of Insect Sprays JohnsonJohnson Quarterly Earnings per Johnson & Johnson Share LakeHuron Level of Lake Huron 1875-1972 LifeCycleSavings Intercountry Life-Cycle Savings Data Loblolly Growth of Loblolly pine trees Nile Flow of the River Nile Orange Growth of Orange Trees OrchardSprays Potency of Orchard Sprays PlantGrowth Results from an Experiment on Plant Growth Puromycin Reaction Velocity of an Enzymatic Reaction Seatbelts Road Casualties in Great Britain 1969-84 Theoph Pharmacokinetics of Theophylline Titanic Survival of passengers on the Titanic ToothGrowth The Effect of Vitamin C on Tooth Growth in Guinea Pigs UCBAdmissions Student Admissions at UC Berkeley UKDriverDeaths Road Casualties in Great Britain 1969-84 UKgas UK Quarterly Gas Consumption USAccDeaths Accidental Deaths in the US 1973-1978 USArrests Violent Crime Rates by US State USJudgeRatings Lawyers' Ratings of State Judges in the US Superior Court USPersonalExpenditure Personal Expenditure Data UScitiesD Distances Between European Cities and Between US Cities VADeaths Death Rates in Virginia (1940) WWWusage Internet Usage per Minute WorldPhones The World's Telephones ability.cov Ability and Intelligence Tests airmiles Passenger Miles on Commercial US Airlines, 1937-1960 airquality New York Air Quality Measurements anscombe Anscombe's Quartet of 'Identical' Simple Linear Regressions attenu The Joyner-Boore Attenuation Data attitude The Chatterjee-Price Attitude Data austres Quarterly Time Series of the Number of Australian Residents beaver1 (beavers) Body Temperature Series of Two Beavers beaver2 (beavers) Body Temperature Series of Two Beavers cars Speed and Stopping Distances of Cars chickwts Chicken Weights by Feed Type co2 Mauna Loa Atmospheric CO2 Concentration crimtab Student's 3000 Criminals Data discoveries Yearly Numbers of Important Discoveries esoph Smoking, Alcohol and (O)esophageal Cancer euro Conversion Rates of Euro Currencies euro.cross (euro) Conversion Rates of Euro Currencies eurodist Distances Between European Cities and Between US Cities faithful Old Faithful Geyser Data fdeaths (UKLungDeaths) Monthly Deaths from Lung Diseases in the UK freeny Freeny's Revenue Data freeny.x (freeny) Freeny's Revenue Data freeny.y (freeny) Freeny's Revenue Data infert Infertility after Spontaneous and Induced Abortion iris Edgar Anderson's Iris Data iris3 Edgar Anderson's Iris Data islands Areas of the World's Major Landmasses ldeaths (UKLungDeaths) Monthly Deaths from Lung Diseases in the UK lh Luteinizing Hormone in Blood Samples longley Longley's Economic Regression Data lynx Annual Canadian Lynx trappings 1821-1934 mdeaths (UKLungDeaths) Monthly Deaths from Lung Diseases in the UK morley Michelson Speed of Light Data mtcars Motor Trend Car Road Tests nhtemp Average Yearly Temperatures in New Haven nottem Average Monthly Temperatures at Nottingham, 1920-1939 npk Classical N, P, K Factorial Experiment occupationalStatus Occupational Status of Fathers and their Sons precip Annual Precipitation in US Cities presidents Quarterly Approval Ratings of US Presidents pressure Vapor Pressure of Mercury as a Function of Temperature quakes Locations of Earthquakes off Fiji randu Random Numbers from Congruential Generator RANDU rivers Lengths of Major North American Rivers rock Measurements on Petroleum Rock Samples sleep Student's Sleep Data stack.loss (stackloss) Brownlee's Stack Loss Plant Data stack.x (stackloss) Brownlee's Stack Loss Plant Data stackloss Brownlee's Stack Loss Plant Data state.abb (state) US State Facts and Figures state.area (state) US State Facts and Figures state.center (state) US State Facts and Figures state.division (state) US State Facts and Figures state.name (state) US State Facts and Figures state.region (state) US State Facts and Figures state.x77 (state) US State Facts and Figures sunspot.month Monthly Sunspot Data, from 1749 to "Present" sunspot.year Yearly Sunspot Data, 1700-1988 sunspots Monthly Sunspot Numbers, 1749-1983 swiss Swiss Fertility and Socioeconomic Indicators (1888) Data treering Yearly Treering Data, -6000-1979 trees Diameter, Height and Volume for Black Cherry Trees uspop Populations Recorded by the US Census volcano Topographic Information on Auckland's Maunga Whau Volcano warpbreaks The Number of Breaks in Yarn during Weaving women Average Heights and Weights for American Women
How to get help on any package?
Crutial in R is to get the list of all members from the package. For that case you use again the
help method but you need to set the package:
The output is huge and shows all R methods from the
How to get the list of all R operators?
This is very easy with the
Syntax command from the
Syntax outlines R syntax and gives the precedence of operators.
The following unary and binary operators are defined. They are listed in precedence groups, from highest to lowest. ':: :::' access variables in a namespace '$ @' component / slot extraction '[ [[' indexing '^' exponentiation (right to left) '- +' unary minus and plus ':' sequence operator '%any%' special operators (including '%%' and '%/%') '* /' multiply, divide '+ -' (binary) add, subtract '< > <= >= == !=' ordering and comparison '!' negation '& &&' and '| ||' or '~' as in formulae '-> ->>' rightwards assignment '<- <<-' assignment (right to left) '=' assignment (right to left) '?' help (unary and binary)
…tags: intro & category: r