Skip to Content
R 语言经典实例(原书第 2 版)
book

R 语言经典实例(原书第 2 版)

by J.D. Long, Paul Teetor
June 2020
Beginner to intermediate
522 pages
9h 6m
Chinese
China Machine Press
Content preview from R 语言经典实例(原书第 2 版)
简单编程
467
作为默认值。在第二种情况下,当
details.csv
文件不可用时,safe_read 将返回该数
据框默认值。
15.8.4 另请参阅
purrr 包中包含用于防止错误的其他函数,请参阅函数 safely 和函数 quietly
如果需要更强大的功能,请使用 help(tryCatch) 来查看 possibly 的功能,其
中包含用于处理错误和警告的复杂操作。它展示了其他编程语言熟悉的 try/catch
范例。
15.9 创建匿名函数
15.9.1 问题
正在使用 tidyverse 中的函数,例如调用需要函数作为参数的 map discard 函数。
你需要一个快捷方式来轻松定义所需要的作为参数的函数。
15.9.2 解决方案
使用 function 定义带参数和函数体的函数,但不要给函数命名,只需使用其内联
定义。
15.9.3 讨论
创建一个没有名称的函数可能看起来很奇怪,但它可以提供方便。
15.3 节中,我们定义了一个函数 is_na_or_null,并用它从列表中删除 NA NULL
元素:
is_na_or_null <- function(x) {
is.na(x) || is.null(x)
}
lst %>%
discard(is_na_or_null)
有时候,编写像 is_na_or_null 这样的微小的一次性函数很烦人。你可以直接使用函
数定义来避免这种麻烦,而不是给它起一个名字:
lst %>%
discard(function(x) is.na(x) || ...
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

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

Aurélien Géron
大规模数据分析和建模:基于 Spark 与 R

大规模数据分析和建模:基于 Spark 与 R

Javier Luraschi, Kevin Kuo, Edgar Ruiz
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey

Publisher Resources

ISBN: 9787111656814