Skip to content
Navigation Menu
Toggle navigation
Sign in
Product
GitHub Copilot
Write better code with AI
GitHub Advanced Security
Find and fix vulnerabilities
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Discussions
Collaborate outside of code
Code Search
Find more, search less
Explore
Why GitHub
All features
Documentation
GitHub Skills
Blog
Solutions
By company size
Enterprises
Small and medium teams
Startups
Nonprofits
By use case
DevSecOps
DevOps
CI/CD
View all use cases
By industry
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
Topics
AI
DevOps
Security
Software Development
View all
Explore
Learning Pathways
Events & Webinars
Ebooks & Whitepapers
Customer Stories
Partners
Executive Insights
Open Source
GitHub Sponsors
Fund open source developers
The ReadME Project
GitHub community articles
Repositories
Topics
Trending
Collections
Enterprise
Enterprise platform
AI-powered developer platform
Available add-ons
GitHub Advanced Security
Enterprise-grade security features
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search or jump to...
Search code, repositories, users, issues, pull requests...
Search syntax tips
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Sign in
Sign up
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
yihui
/
r-ninja
Public
Notifications
You must be signed in to change notification settings
Fork
327
Star
839
Code
Issues
13
Pull requests
0
Actions
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security
Insights
Files
master
Breadcrumbs
r-ninja
/
03-data-structure.Rmd
Copy path
Blame
Blame
Latest commit
History
History
39 lines (25 loc) · 1.29 KB
master
Breadcrumbs
r-ninja
/
03-data-structure.Rmd
Top
File metadata and controls
Code
Blame
39 lines (25 loc) · 1.29 KB
Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#
数据结构 {#data-structure}
了解一门语言,当然要从它的数据结构开始,否则你无法操纵程序中的对象。这对单身忍者尤其重要:有时候胡子拉碴忙活了大半夜,突然程序告诉你连对象都找不到,你悲催的心情,一定凉过杜甫的茅屋为秋风所破歌。
![
对象很重要
]
(
https://i.imgur.com/KD3EZ.jpg
)
##
向量
忍者判断数值相对大小从来不用大于小于或等号,也从来不目测,因为在浮点数运算中,大小比较从来不靠谱。以下这事儿让COS的R版主都震惊了(
<
http://cos.name/cn/topic/106794
>
):
```
{r
point-six}
x=seq(0,1,by=0.2)
y=seq(0,1,by=0.2)
y[4]
x[3]
1-x[3]
y[4]>1-x[3]
```
竟然出现了0.6大于0.6的情况,版主大人大呼坑爹。当时我的回帖是:
>
作为R版版主,应该做到在凌晨四点突然被人叫醒问你10乘以0.1等于几,你在1秒钟之内斩钉截铁回答,不是1!(R FAQ 7.31)。
简单来说就是浮点数在计算机中的表达有限制,不能以任意精度存储,所以尤其是微小的数字或巨大的数字在运算时经常会有些意外情况。再举几个例子:
```
{r
float-point-ex}
seq(0,1,.1)
seq(0,1,.1)==c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
.3-.7+.4==0
sqrt(2)^2==2
```
##
矩阵
##
数据框
##
列表
You can’t perform that action at this time.