Preview

Introduction to R

Better Essays
Open Document
Open Document
3573 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Introduction to R
R as a Tool for Statistical Analysis

Getting Started with R (Part I)
The > is called the prompt. If a command is too long to fit on a line, a + is used for the continuation prompt.
Assign values to an object using the equal sign (=), e.g., >x=11. Note: R is case sensitive
Print command allows you to see the value in an object
You may also use the less than sign and a dash to create an arrow (<-) to assign values. An equal sign (=) is also used to assign values.
R easily overwrites objects, e.g. >x=9, 11 is overwritten) ls() command allows to see what is stored in R’s memory, we can look at the workspace in R to look at the memory rm command removes a an object from R’s memory, e.g., >rm(x)
Objects in r may include numbers or periods, e.g., >x.1=14
We may also assign character values to R rather than numbers by including quotation marks around the characters, e.g., >xx=”Statistics”. Note: when numbers are in quotation marks, R will treat them as characters not numbers
We may perform arithmetic operations in R, e.g., >11+14
We may also perform the same operations in objects in R, e.g. > x+x.1
We may wish to store this in a new object called z, i.e., >z=x.1+12
We can also perform other arithmetic operations, e.g. > 10^2
We can take the square root using the sqrt command, e.g., >sqrt(x), or >y^(1/2)
We can take the natural logarithm using the log command, e.g. >log(y)
We can take the exponent using the exp command, >exp(x)
We can also calculate log of other bases using the log base 2 command, e.g., >log2^(x)
We can calculate the absolute value using the abs command, e.g. >abs(-14)
Few helpful tips in using R:
If you enter an incomplete command, R will follow that up with a plus sign to let you know there’s an incomplete command, e.g., >sqrt(x the plus sign will appear then just add ) for R to return the answer
Using the arrow up key in the key board will bring you to the last

You May Also Find These Documents Helpful