Skip to Content
高效R语言编程
book

高效R语言编程

by Colin Gillespie, Robin Lovelace
August 2018
Intermediate to advanced
227 pages
4h 16m
Chinese
China Electric Power Press Ltd.
Content preview from 高效R语言编程
128
6
introduction.html
)开始了解
dplyr
3.
wb_ineq 数据集上测试另外
dplyrverbs[
输入 vignettepackage =
"
dplyr
"
)可找到更多的
vignette
名字
]
非标准计算
最后有一个关于
dplyr
包的话题不是关于数据的,而是关于该函数语法的。
请注意本节代码例程中的很多参数使用没有引号包裹的原始名字(例如
用的是 Country,而不是 " Country")。
这称为非标准计算(
NSE
)(见
vignette(
"
nse
"
))。
特意采用
NSE
,是为了更高效地交互使用函数。
NSE
减少了键盘输入并允许在
RStudio
中自动完成。
当使用交互式
R
时,这是非常好的。
但当你要非交互地使用
R
时,通常使
用标准计算更健壮,因为它将模糊范围之类的
bug
降到最低。
如果你将代码
包含在包中,使用标准计算也避免了不得不声明全局变量。
基于这个原因,
tidyr
dplyr
中的多数函数有两个版本:一个使用
NSE
(默认),另外一个
使用标准计算并要求引号包裹的变量名。
函数的标准计算版本使用
_
后缀标
识。下面代码中的 gather() 功能说明这点:
# 1:
默认的
NSE
函数
group_by(cars, cut(speed, c(0, 10, 100))) %>% summarize(mean(dist))
#> # A tibble: 2
×
2
#> `cut(speed, c(0, 10, 100))` `mean(dist)`
#> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

数据科学之编程技术:使用R进行数据清理、分析与可视化

数据科学之编程技术:使用R进行数据清理、分析与可视化

迈克尔 弗里曼, 乔尔 罗斯
R数据科学

R数据科学

Hadley Wickham, Garrett Grolemund

Publisher Resources

ISBN: 9787519820855