0% found this document useful (0 votes)
5 views3 pages

R Coding Cheatsheet

Uploaded by

gabriellehsy2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

R Coding Cheatsheet

Uploaded by

gabriellehsy2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Cheatsheets / Learn R

Learn R: Introduction

R Logical Data Type

The R logical data type has two possible values - TRUE or


FALSE .
It is important for the capitalization to stay as shown and to
make sure not to wrap the values in quotes.

NA Data Type in R

R conveys an absence of value with the keyword NA (no


quotes). There is a numeric NA, a character NA, and a
logical NA. Each means a non value within its context.

Mathematical Operations in R

In R, the conventional symbols +, -, *, and / are # Results in "500"


used for addition, subtraction, multiplication, and division.
573 - 74 + 1
The PEMDAS order of operations governs these
mathematical operations in R.
# Results in "50"
25 * 2

# Results in "2"
10 / 5
R Data Types

In R, and in programming in general, data types are the # var1 has the number data type
classifications that we give to different kinds of information
pieces.
var1 <- 3
Specifically, R provides the following basic data types:
character, numeric, integer, logical, and complex. Each # var2 has the character data type
data type is used to represent some type of info -
var2 <- "happiness"
numbers, strings, boolean values, etc.

# var3 has the logical data type


var3 <- TRUE

R Conditional Statements

In R, a conditional statement goes inside parentheses and if (n == 5) {


is followed by a set of curly braces that contain the code to
print('n is equal to five')
be executed.
In an if statement, if the conditional is True then the code }
inside the curly braces is executed.

R Comments

R interprets anything on a line after a # symbol as a # This is a comment!


comment.
Comments can be used to add text in the program that will
NOT be executed. They are useful for providing context,
hints for yourself or others working on the code, or even to
temporarily get rid of a line when debugging.

R’s Character Data Type

R’s character data type includes all string values. A


character is denoted by its surrounding quotation marks.
Characters are any text or grouping of keyboard
characters, including letters, numbers, spaces, symbols,
etc. The character version of a number is the text
conveying a number. The number itself, without quotes, is
numeric.
Assignment Operator in R

In R, there are two ways to assign values to variables. We


can use the assignment operator, an arrow sign ( <- )
made with a carat and a dash. It is also acceptable, though
less preferred, to use an equal sign ( = ).

R Numeric Data Type

The numeric data type in R is a class that represents example <- 4


numbers that can be integers or decimals.
another.example <- 15.2

Print Share

You might also like