Every experiment starts with data, so the question is "how do you enter your data into R?". Well there are many ways to do that, but for this post, we will only consider the two functions below:
Where
What happened here is that, we defined a new object,
For dispersion, try this,
What about the
What we did here is we defined two R objects, the
And the mean of the
- The concatenate,
c
; and, - the
data.frame
functions.
c
, is use for combining data points into single numeric R object, known as the vector. The usage of this function is simply
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c(..., recursive = FALSE) |
...
is the objects to be concatenated. Run ?c
, for description of the second argument. Let's try an example,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec1 <- c(0.5, 0.3, 0.1, 0.6, 0.2) | |
vec1 | |
# OUTPUT | |
[1] 0.5 0.3 0.1 0.6 0.2 |
vec1
, into the workspace. We can then start manipulating the entries, say using the summary,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
summary(vec1) | |
# OUTPUT | |
Min. 1st Qu. Median Mean 3rd Qu. Max. | |
0.10 0.20 0.30 0.34 0.50 0.60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var(vec1) # Variance | |
# OUTPUT | |
[1] 0.043 | |
sd(vec1) # Standard Deviation | |
# OUTPUT | |
[1] 0.2073644 |
data.frame
function? If the first function combines data points into a single vector, data.frame
from the name itself constructs a frame of data points. Here is an example,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
weights <- c(56.4, 45.6, 40.2, 50.1, 51.3) | |
volunteers <- c("Mirra", "Jeh-Jeh", "Amil", "Ikkah", "NG") | |
data1 <- data.frame(volunteers, weights) | |
data1 | |
# OUTPUT | |
volunteers weights | |
1 Mirra 56.4 | |
2 Jeh-Jeh 45.6 | |
3 Amil 40.2 | |
4 Ikkah 50.1 | |
5 NG 51.3 |
weights
and volunteers
, then we combine the two into a table like structure, called the data frame. To extract columns of data1
, try this,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extract volunteers | |
data1$volunteers | |
# OUTPUT | |
[1] Mirra Jeh-Jeh Amil Ikkah NG | |
Levels: Amil Ikkah Jeh-Jeh Mirra NG | |
# extract weights | |
data1$weights | |
#OUTPUT | |
[1] 56.4 45.6 40.2 50.1 51.3 |
weights
is,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mean(data1$weights) | |
# OUTPUT | |
[1] 48.72 |