2 + 3
## [1] 5
2 - 3
## [1] -1
2 * 3
## [1] 6
2 / 3
## [1] 0.6666667
2 ^ 3
## [1] 8
2 %% 3
## [1] 2
2 %/% 3
## [1] 0
2 == 3
## [1] FALSE
2 != 3
## [1] TRUE
2 > 3
## [1] FALSE
2 < 3
## [1] TRUE
2 >= 3
## [1] FALSE
2 <= 3
## [1] TRUE
!TRUE
## [1] FALSE
!FALSE
## [1] TRUE
TRUE & TRUE
## [1] TRUE
TRUE & FALSE
## [1] FALSE
TRUE | FALSE
## [1] TRUE
FALSE | FALSE
## [1] FALSE
a <- 3
a
## [1] 3
4 -> a
a
## [1] 4
c(1,3,5)
## [1] 1 3 5
c('a', 1, 3)
## [1] "a" "1" "3"
c(FALSE, 1, 3)
## [1] 0 1 3
1:10
## [1] 1 2 3 4 5 6 7 8 9 10
seq(0, 10, by = 2)
## [1] 0 2 4 6 8 10
seq(0, 10, length.out = 4)
## [1] 0.000000 3.333333 6.666667 10.000000
-way 1:
vec1 <- c(1, 3, 5, 7, 9)
print(vec1)
## [1] 1 3 5 7 9
-way 2:
vec2 <- seq(from = 1, to = 9, by = 2)
print(vec2)
## [1] 1 3 5 7 9
-way 3:
vec3 <- rep(c(1, 3, 5, 7, 9), times = 1)
print(vec3)
## [1] 1 3 5 7 9
my_vector = c('a','p','p','l','e')
my_vector[1]
## [1] "a"
my_vector[-1]
## [1] "p" "p" "l" "e"
my_vector[2:4]
## [1] "p" "p" "l"
my_vector[c(2,4)]
## [1] "p" "l"
x = 1:10
x[x > 5]
## [1] 6 7 8 9 10
x[x != 5]
## [1] 1 2 3 4 6 7 8 9 10
x[x <= 5]
## [1] 1 2 3 4 5
The result of x[y > 5] is error, because y is not defined
###Try the following code and see what it gives to you. Can you explain why the result is what you observed?
mean(trim = 0, na.rm = T)
## Error in mean.default(trim = 0, na.rm = T): argument "x" is missing, with no default
my_data <- c(1, 2, 2, 5, 10, NA)
mean(my_data, trim = 0, na.rm = TRUE)
## [1] 4
mean(my_data)
## [1] NA
mean(my_data, trim = 0.2)
## [1] NA
mean(my_data, trim = 0.2, na.rum = T)
## [1] NA
X.4 because we calculate
the mean after removing missing values.NA because
na.rm is set to FALSE by default.NA because
na.rum is a misspelling, so na.rm remains its
default value, FALSE.my_data <- data.frame(name = c('James', 'Alice', 'Lucy'), Math_grade = c(80, 90, 100), English_grade = c(100, 90, 80))
my_data
## name Math_grade English_grade
## 1 James 80 100
## 2 Alice 90 90
## 3 Lucy 100 80
my_data$name
## [1] "James" "Alice" "Lucy"
my_data$Math_grade
## [1] 80 90 100
my_data$English_grade
## [1] 100 90 80
my_data[1, ]
## name Math_grade English_grade
## 1 James 80 100
my_data[2, ]
## name Math_grade English_grade
## 2 Alice 90 90
my_data[3, 3]
## [1] 80
1. What is the population of this study? Answer: All individuals diagnosed with Stage I breast cancer.
2. What is the sample of this study? Answer: 1,225 newly diagnosed breast cancer cases
3. What is the random variable of this study? Answer: the average seven-year survival rates for Stage I breast cancer
1. Under what condition is the study descriptive? Answer: We drew conclusions by collecting overweight data from all Americans.
2. Under what condition is the study inferential? Answer: We used data from a subset of Americans as a sample to draw conclusions and then predicted the overall overweight situation of the entire U.S. population.
3. Which one is more likely to be the case? Answer: The second station is more likely because it is difficult to obtain data from all Americans.
1. categorical but not ordinal *Answer:The list of deaths in a fire
2. ordinal *Answer:The severity of fire
3. discrete numeric *Answer: The number of deaths of a fire
4. continuous numeric *Answer: Temperature