
# list all functions containing string fooĮxample( foo) # show an example of function foo Going Further At the program's command prompt you can use any of the following: Once R is installed, there is a comprehensive built-in help system. Search() # see packages currently loaded Getting Help Once installed, they have to be loaded into the session to be used.

Others are available for download and installation. The directory where packages are stored is called the library. Packages are collections of R functions, data, and compiled code in a well-defined format. The next line of code adds a regression line to this graph. The plot( ) function opens a graph window and plots weight vs. In R, graphs are typically created interactively. Possible functions used in sapply include mean, sd, var, min, max, median, range, and quantile. # get means for variables in data frame mydata One way to get descriptive statistics is to use the sapply( ) function with a specified summary statistic.īelow is how to get the mean with the sapply( ) function: R provides a wide range of functions for obtaining summary statistics. Sep=",", row.names="id") Descriptive Statistics Mydata <- read.table("c:/mydata.csv", header=TRUE, # note the / instead of \ on mswindows systems # first row contains variable names, comma is separator R offers options to import many file types, from CSVs to databases.įor example, this is how to import a CSV into R. Note that by using built-in functions, the only thing you need to worry about is how to effectively communicate the correct input arguments (arglist) and manage the return value/s (if any). The code in between the curly braces is the body of the function. In R, a function is defined with the construct: A function is a piece of code written to carry out a specified task it may accept arguments or parameters (or not) and it may return one or more values (or not!). # An example of computing the mean with variablesĪlmost everything in R is done through functions.

Use the assignment operator <- to create new variables. R has a wide variety of data types including scalars, vectors (numerical, character, logical), matrices, data frames, and lists. Note that binary operators work on vectors and matrices as well as scalars.

R's binary and logical operators will look very familiar to programmers. Graphic User InterfacesĪside from the built in R console, RStudio is the most popular R code editor, and it interfaces with R for Windows, MacOS, and Linux platforms.

At the end of an R session, the user can save an image of the current workspace that is automatically reloaded the next time R is started. The workspace is your current R working environment and includes any user-defined objects (vectors, matrices, data frames, lists, functions). The user enters commands at the prompt ( > by default) and each command is executed one at a time. StartupĪfter R is downloaded and installed, simply find and launch R from your Applications folder. Software can be downloaded from The Comprehensive R Archive Network (CRAN). R is available for Linux, MacOS, and Windows.
