-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
applied new template and reorganized a bit
- Loading branch information
WandrilleD
committed
Jan 3, 2024
1 parent
b72dffc
commit 9d6c6b6
Showing
5 changed files
with
75 additions
and
85 deletions.
There are no files selected for viewing
Binary file not shown.
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
# 1) Create two vectors, "vector_a" and "vector_b", containing the values from −5 to 5 and from 10 down to 0, respectively. | ||
vector_a <- -5:5 | ||
vector_b <- seq(10,0) # alternatively: vector_b <- c(10,9,8,7,6,5,4,3,2,1,0) | ||
|
||
# 2) Calculate the (elementwise) sum, difference and product between the elements of "vector_a" and "vector_b". | ||
vector_a + vector_b #sum | ||
vector_a - vector_b #difference | ||
vector_a * vector_b #product | ||
|
||
# 3) a) Calculate the sum of elements in "vector_a" | ||
# b) Calculate the overall sum of elements in both "vector_a" and "vector_b". | ||
sum(vector_a) | ||
sum(vector_a, vector_b) # alternatively : sum(vector_a + vector_b) | ||
|
||
|
||
# 4) Identify the smallest and the largest value among both "vector_a" and "vector_b". | ||
min(vector_a, vector_b) | ||
max(vector_a, vector_b) | ||
|
||
# 5) Compute the overall mean of the values among both "vector_a" and "vector_b" | ||
mean( c( vector_a, vector_b) ) # mean() works only on a single vector, unlike sum, min and max! | ||
# Concatenate both vectors (using c() ) before computing the mean | ||
|
||
# 1) Create two vectors, "vector_a" and "vector_b", containing the values from −5 to 5 and from 10 down to 0, respectively. | ||
vector_a <- -5:5 | ||
vector_b <- seq(0,1,0.1) # alternatively (0:10)*0.1 | ||
|
||
# 2) Calculate the (elementwise) sum, difference and product between the elements of "vector_a" and "vector_b". | ||
vector_a + vector_b #sum | ||
vector_a - vector_b #difference | ||
vector_a * vector_b #product | ||
|
||
# 3) a) Calculate the sum of elements in "vector_a" | ||
# b) Calculate the overall sum of elements in both "vector_a" and "vector_b". | ||
sum(vector_a) | ||
sum(vector_a, vector_b) # alternatively : sum(vector_a + vector_b) | ||
|
||
|
||
# 4) Identify the smallest and the largest value among both "vector_a" and "vector_b". | ||
min(vector_a, vector_b) | ||
max(vector_a, vector_b) | ||
|
||
# 5) Compute the overall mean of the values among both "vector_a" and "vector_b" | ||
mean( c( vector_a, vector_b) ) # mean() works only on a single vector, unlike sum, min and max! | ||
# Concatenate both vectors (using c() ) before computing the mean | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
|
||
# 1)Install and load the package MASS (or other CRAN packages). | ||
# install.packages("MASS") | ||
# 1) The following command lines loads the MASS library and the bacteria data.frame present in the MASS package. Execute it: | ||
library(MASS) | ||
|
||
|
||
# 2) The following command line loads the bacteria data.frame present in the MASS package. Execute it: | ||
|
||
data(bacteria) | ||
?bacteria | ||
|
||
# 3) What are the names of the columns of the bacteria data.frame ? | ||
# 2) What are the names of the columns of the bacteria data.frame ? | ||
|
||
names(bacteria) | ||
|
||
# 4) Use the [] , to select in bacteria rows 100 to 119 in the column "ap". | ||
# 3) Use the [] , to select in bacteria rows 100 to 119 in the column "ap". | ||
|
||
bacteria[ 100:119 , "ap" ] | ||
|
||
# 5) Use $ to get the column "week" and check how many missing values it has. | ||
|
||
sum(is.na(bacteria$week)) | ||
# 4) Use $ to get the column "week" and check how many 0 values it has. | ||
|
||
#Optional : 6) use comparison operators to count how many rows correspond to a “placebo” treatment (“trt” column). | ||
sum(bacteria$week == 0) | ||
|
||
sum(bacteria$trt == "placebo") | ||
# 5) Optional : using a comparison operator and [], select the rows which correspond to a “placebo” treatment (in the “trt” column). | ||
|
||
bacteria[ bacteria$trt == "placebo" , ] |