Day_1 Part_1 Data type in R :classes and structures

本文介绍了R语言的基础知识,包括其面向对象的特性以及各种数据类型,如数值、整数、字符、逻辑和复数等。同时,文章提到了R中类和结构的概念,以及特殊值的处理,如缺失值NA和非数字值NaN。此外,还讨论了R中检查和转换数据类型的方法,如`typeof()`、`class()`和`str()`等函数的使用。文章还简要提及了逻辑值的表示以及因素(factor)在分类数据中的应用。
摘要由CSDN通过智能技术生成

1. Introduction

R is an object-oriented programming language. Almost anything in R could be an object.
请添加图片描述

2. Datatype in R

a. Summary

decimal numbers
whole numbers
characters/strings
TRUE/FALSE
categorical
Not a number
Not applicable
infinity
Datatype in R
Classes
Structure
Special values
numeric
integer
character
logical
complex
factor
vector
matrix/array
data.frame
list
NaN
NA
Inf/-Inf

NB:
(1) numeric class in R should be double/floating point.
(2) We would say factor is something between class and structure. It is a structure but behave more like a class.
(3) Different with python, we call string as character in R.
(4) Some useful function to check the type of an object:

FunctionApplication
typeof()what is it? i.e. how is it saved in memory? (not common used)
class()what is it? i.e. how is it used in functions?
str()what is the structure? (frequently used, also tell you class)

(5)
Conversion between different classes/structures: as.numeric(), as.logical(), as.integer(), as.factor(), as.character(), as.matrix(), as.list, as.data.frame()
Logical test for class/structures of object: is.numeric(), is.logical(), is.integer(), is.factor(), is.character(), is.matrix(), is.list(), is.data.frame()

b. Logical values

Logical values are created by logical expressions. When coerced to numeric, TRUE = 1, FALSE = 0.
logical operators:

OperatorsUse
>less than
>=less than or equal
<greater than
<=greater than or equal
==equal to
!=not equal
!not
&and
|or

c. factor

Factors used for classification - categories
Take gender as an example:

d. special values

Missing numbers are NA
Undefined numbers (e.g. division by zero) are NaN

3. Frequently-used function:

Functionapplication
c(x1, x2)combine things together
min(x)minimum value
max(x)maximum value
range(x)get the range.same as c(min(x),max(x))
length(x)get the length of x
sort(x) ; order(x, …)sorting
sum()sum
prod()product
mean(), median(), sd(), var()statistical functions to get mean, median, standard derivation, variance
summary(x)statistical summary
paste()see example below (detail see in ?paste())

paste() 函数:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值