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 版)
184
6
其指定类型的对象,因此可以将它们放在原子向量中。例如,我们可以使用 map_chr 函数
要求 R 将结果强制转换为字符型输出,或使用 map2_dbl 函数以确保结果是双精度型输出:
map2_chr(a, b, gcd)
#> [1] "1.000000" "2.000000" "3.000000"
map2_dbl(a, b, gcd)
#> [1] 1 2 3
如果我们的数据有两个以上的向量,或者数据已经在列表中,我们可以使用 pmap 系列
函数,它将列表作为输入:
lst <- list(a,b)
pmap(lst, gcd)
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
#> [[3]]
#> [1] 3
或者如果我们想要一个向量作为输出:
lst <- list(a,b)
pmap_dbl(lst, gcd)
#> [1] 1 2 3
使用 purrr 函数时,请记住 pmap 系列是平行映射器,它将
列表
作为输入,而 map2
数将两个
向量
(并且只有两个向量)作为输入。
6.5.4 另请参阅
这实际上只是 6.1 节的一个特例。有关 map 函数变体的更多讨论,请参阅该方法。此
外,Jenny Bryan 在她的 GitHub 网站(
https://jennybc.githup.io/purrrtutorial/
)上收集了
大量的 purrr 教程。
6.6 将函数应用于一组数据
6.6.1 问题
你的数据元素以组的形式出现。你需要按组处理数据,例如,按组求和,或者按组求平均值。 ...
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