Sunteți pe pagina 1din 4

Frequently Asked Questions

What is R?
R is a programming language and software environment for statistical computing and graphics.
The R language is widely used among statisticians and data miners for developing statistical
software. R is an implementation of the S programming language combined with lexical
scoping semantics inspired by Scheme. S was created by John Chambers while at Bell Labs.
What is RStudio?
RStudio is a free and open source integrated development
a programming language for statistical computing and graphics.

environment (IDE)

for R,

RStudio is available in two editions: RStudio Desktop, where the program is run locally as a
regular desktop application; and RStudio Server, which allows accessing RStudio using a web
browser while it is running on a remote Linux server. Prepackaged distributions of RStudio
Desktop are available for Microsoft Windows, Mac OS X, and Linux.
Why R is named R?
The name is partly based on the (first) names of the first two R authors (Robert Gentleman and
Ross Ihaka), and partly a play on the name of the Bell Labs language S
What is S?
S is a very high level language and an environment for data analysis and graphics.
What machines does R run on?
R is being developed for the Unix-like, Windows and Mac families of operating systems.
Support for Mac OS Classic ended with R 1.7.1.
What is CRAN?
The Comprehensive R Archive Network (CRAN) is a collection of sites which carry identical
material, consisting of the R distribution(s), the contributed extensions, documentation for R, and
binaries.
What is the difference between package and library?
A package is a standardized collection of material extending R, e.g. providing code, data, or
documentation. A library is a place (directory) where R knows to find packages it can use (i.e.,
which were installed). R is told to use a package (to load it and add it to the search path) via

calls to the function library. I.e., library() is employed to load a package from libraries containing
packages.
What R packages do I already have?
To get a list of installed packages, execute library() at the R prompt. R will first list all the
packages installed in your local R directory and then it will list all of the packages installed
globally on your system
#list all R packages installed
> library()
How can I find additional information about R packages I have?
If you would like to get additional information about the installed packages you can access it
using installed.packages() at the R prompt
#obtain information about installed R packages
> installed.packages()
How do I install and Remove a new package?
Install from CRAN directly. A package can be installed using install.packages("package
name") at the R prompt.
# Install xxx package
> install.packages("xxx")
A package can be removed using remove.packages("package name") at the R prompt:
# Remove xxx package
> remove.packages("xxx")
Where are my R packages installed?
You can view the list of the packages along with their paths running path.package() at the R
prompt
#where are my R packages installed
> path.package()
I installed a package but the functions are not there
To actually use the package, it needs to be loaded using library().

How to load installed packages and search currently installed packages?


Before you can use a package, you have to load it into R by using the library() function.
#load xxx package
> library(xxx)
#see packages currently loaded
> search()
How to unload the packages?
If you want to unload a package, youll have to use some R magic. The detach() function will let
you do this, but you have to specify that its a package youre detaching, like this
#unload the xxx packages
> detach(package:xxx)
How to set and get working directory in R?
R is always pointed at a directory on your computer. You can find out which directory by
running the getwd (get working directory) function; this function has no arguments. To change
your working directory, use setwd and specify the path to the desired folder.
#get working directory
getwd()
#set working directory
setwd(dir)
dir Specify a working directory. This may be from the root directory (starting with / on a Mac),
it may include a double-dot (..) to move locally up a folder from the current directory, and it may
include a path from the current directory.

How to read/import files in R?


#read files in R
read.filetype(Filename)
read.csv(filename.csv) #read .csv file

How to remove object from specified environment?


#remove x from the workspace
rm(x)
How to list the objects in the current workspace?
# list the objects in the current workspace
ls()
How can we use the previous commands?
#work with your previous commands
history() # display last 25 commands
history(max.show=Inf) # display all previous commands
How to save and load the command history in a separate file?
# save your command history
savehistory(file="myfile")
# recall your command history
loadhistory(file="myfile")
How to quit R? You will be prompted to save the workspace
# quit R
q()

S-ar putea să vă placă și