3 + 5
[1] 8
Keep the intro.R
script open, but now type directly into the R console below.
3 + 5
[1] 8
What happens to the output?
Assign an R object called juice
to be equal to 4+4
. What is the output when you type juice
?
<- 4 + 4
juice
# juice
Can you describe what you think x
indicates below?
<- c(1,7,9)
x 2] x[
[1] 7
The notation c()
in R stands for combine. We used this a lot in R because we are often combining data and comparing it with another dataset.
What do you think the R object fruit
is?
<- 5
apples <- 6
oranges
<- apples + oranges fruit
Symbols in R are used in arguments, logical statements, assignments, and more. We will use many of them, but the common ones
# <- vs. =
= 3 + 4
a <- 3 + 4 a
# Errors and improper R object naming
# 6389/
# 5-6
# 5.6 <- fruit
There are several ways to view or look at an R object. Can you figure out what they are?
Calculate the volume of a sphere, where the diameter is 20 meters.
Make sure current you keeps track of everything. Future you will Thank past you.
Also use the pound symbol or hashtag mark, “#” to comment out code.
# This code adds the values x and y, creating an R object called 'answer'
answer <- x + y
x <- 5
y <- x^2
## We can set x equal a specific value to define x, y, and answer.