第一天 r语言学习

2019/09/15 开始学习R语言(链接:https://www.bilibili.com/video/av6268508?from=search&seid=6572374907001663901)

  1. 查看已安装的包: installed.packages()

  2. 移除单个变量: rm(object) #object = 变量名字

  3. 移除所有变量: rm(list = ls())

  4. 查看所有变量: list(ls())

  5. R语言不支持多行注释,但可以实现多行注释:

    if(FALSE) { “This is a demo for multi-line comments and it should
    be put inside either a single
    OR double quote” }

    myString <- “Hello, World!” print ( myString)

  6. R的数据类型
    6.1 经常使用的数据类型: 向量vector、 列表list、 矩阵matrix、数组array、 因子factor、 数据帧dataframe;
    6.2 最基本 逻辑性logical、 数字Numeric、 整型integer、复合型complex、 字符character、原型Raw

  7. 列表list 中的元素可以是不同的 可以是向量、列表、函数等

  8. 注意list列表的创建时 list1 <- list()

  9. 注意矩阵的创建格式是: matrix1 <- matrix(c(),nrow= , ncol = , byrow = TRUE)

  10. 矩阵被限制为二维, array(数组)则打破了这个限制,使用dim属性,注意数组的创建,是array(c(), dim=c())

#create a array
array1 <- array(c("a", "b"),dim = c(3,3,3))
class(array1)
print(array1)
  1. 因子factor及其创建
#create a factor 
apple_colors <- c("green","red","green","green", "yellow","red")
factor_apple <- factor(apple_colors)
print(factor_apple)
print(nlevels(factor_apple)
  1. DATAFrame 数据帧: 表格数据对象,同一列数据类型相同,不同列数据之间类型可以不同

  2. %/% : 两个向量相除求商

v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v%/%t)

  1. 所有大于1的数字被认为是逻辑值TRUE;
  2. &:逻辑and,两个向量对应位置进行运算;
  3. !:逻辑not ,两个向量对应位置进行运算;
  4. | : 逻辑or, 两个向量对应位置进行运算;
  5. && : 取两个向量的第一个元素进行 & 运算;
  6. || : 取两个向量的第一个元素进行 | 运算;
  7. %in% : 此标识符用来判断 与元素是否属于向量;
v1 <-  10
v3 <- 44
t <- 1:20
print(v1 %in% t)
print(v3 %in% t)
> print(v1 %in% t)
[1] TRUE
> print(v3 %in% t)
[1] FALSE
  1. 获取r包的库位置: .libpaths()
  2. 获取在当前r环境中加载的所有包: search()
  3. 查看r下载的所有包: library()
  4. repeat循环框架: 循环体必然至少执行一次
repeat {
commands
if(conditions) {
      break
      }
    }

25.while循环 可以做到一次都不循环,因为他是先判断再执行

while(conditions){
commands
}
  1. 可以用cbind(c1, c2, c3)函数将c1, c2, c3 三个向量黏合成一个dataframe。
  2. 函数的创建
函数名 <- function([参数]){
             commands
  }	

 28. 连接字符串函数: paste()>>>>>>>>>>paste(... , sep = ' ',  collapse = NULL)
 ... : 表示要接合的任意数量的自变量;
 sep:  表示接合之后自变量之间的分割,‘ ’ 即表示空格分隔;
 collapse: 消除接合后变量与变量之间的空格;
 

c1 <- “hello”
c2 <- “how are you”
c3 <- “i am fine”
c <- paste(c1, c2, c3, sep = ‘’,collapse = ‘’)
print©
[1] “hellohow are youi am fine”


 29. List item

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值