Datacamp Notes: Introduction to R

Introduction to R


Intro to basics

  • basic types
    • numerics
    • integers
    • logical
    • characters

Vectors

names()
sum()
  • logical comparison operators
    - < for less than
    - > for greater than
    - <= for less than or equal to
    - >= for greater than or equal to
    - == for equal to each other
    - != not equal to each other

Matrices

matrix()
rowSums()
colSums()
cbind()
rbind()

Example:

ticket_prices <- matrix(c(5, 5, 6, 6, 7, 7), nrow = 3, byrow = TRUE, dimnames = list(movie_names, col_titles)) 

Factors

factor()
levels()
summary()
  • two types of categorical variables:
    • nominal categorical variable
    • ordinal categorical variable
      Example:
factor(some_vector, ordered = TRUE, levels = c("Level_1", "Level_2" ...))

Data frames

head()
tail()
str()
data.frame()
subset()
a[order(a)]

Lists

list()

Example: select the second component,the first element

shining_list[[2]][1] 

Conclusion

  • Vectors (one dimensional array): can hold numeric, character or logical values. The elements in one vector all have the same datatype.
  • Matrices (two dimensional array): can hold numeric, character or logical values. The elements in one matrix all have the same datatype.
  • Data frames (two-dimensional objects): can hold numeric, character or logical values. Within a column all elements have the same data type, but different columns can be of different data type.
  • List: a variety of objects under one name (that is, the name of the list) in an ordered way. These objects can be matrices, vectors, data frames, even other lists, etc. It is not even required that these objects are related to each other.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值