0
点赞
收藏
分享

微信扫一扫

Day_1 Part_1 Data type in R :classes and structures

一世独秀 2022-02-06 阅读 172
r语言

1. Introduction

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

2. Datatype in R

a. Summary

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)

b. Logical values

Logical values are created by logical expressions. When coerced to numeric, TRUE = 1, FALSE = 0.
logical operators:
请添加图片描述
请添加图片描述

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() 函数:
请添加图片描述

举报

相关推荐

0 条评论