R 系统内调用解释文档
help(log) # help('log') and ?log will also work.
help("*") # Enclose special characters in quotation marks.
example(log) # short code segments near the end of the help document
R调包
R Version at least 4.2.1, and RStudio Version at least 2022.07.1+554
required_packages <- c("rmarkdown", "tidyverse")
installed_packages <- rownames(installed.packages()) # installed.packages() is a data frame with info about versions and other things we don't need.
to_install <- setdiff(required_packages, installed_packages) # Which ones are required but not installed?
install.packages(to_install) # Install them.
#Then load a package
library(rmarkdown)
简易实现
installed.packages("rmarkdown")
library(rmarkdown)
R的计算器功能
sin(2 * pi/3) # <--- this symbol is for comments.
## [1] 0.8660254
5^2 # Same as 5**2.
## [1] 25
5%%2 # Remainder after dividing 5 by 2.
## [1] 1
sqrt(4) # Square root of 4.
## [1] 2
log(1) # Natural logarithm of 1.
## [1] 0
R的函数设置
# log(x, base = exp(1)) is the format of the logarithm function
log(exp(2))
## [1] 2
# If you don't specify the base, it is defaulted at e
# Of course, you can change the base
log(8, 2)
## [1] 3
# You can also explicitly change a function input using the '=' symbol
log(8, base = 2)
## [1] 3
log(base = 2, 8) # Order won't matter when you explicitly name an input
## [1] 3
x <- 1 # assigns x to the value of 1.
x # Display.
y <- 2 # assigns y to the value of 2
x + y
## [1] 3
name <- "Walter Elias Disney" # assigns a string instead of a number. Either single or double quotes can be used interchangeably.
f <- function(x) {
x