记忆复建|R语言基础语法

本文介绍了R语言的基础语法,包括系统内调用解释文档、调包、作为计算器的功能、函数设置、数据类型检测、逻辑运算、数据结构如向量、矩阵和数据框架的使用,如nrow、ncol等属性。
摘要由CSDN通过智能技术生成

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 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值