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语言编程
高效数据木匠
129
合并数据集
有时通过与其他数据的合并可大大增强数据集的作用。比如说
,如果将全局
ghg_ems 数据集与地理数据合并
,我们能够可视化气候污染的空间分布。基
于本章的目的
,我们将 ghg_ems
ggmap
提供的
world
数据连接,演示了数
据连接的概念以及方法(也称为合并
)。
library("ggmap")
world = map_data("world")
names(world)
#> [1] "long" "lat" "group" "order" "region" "subregion"
world
的新数据集
ghg_ems 进行可视化比较
(例如
View(world);
View(ghg_ems))。显然
world
的新数据集中的 region 列与 ghg_ems 中的
Country 列包含的信息相同。这将是连接变量,在 world 中对其改名将使连
接更高效。
world = rename(world, Country = region)
ghg_ems$All = rowSums(ghg_ems[3:7])
确保两个连接变量有相同的类(组合字符与因子列将导致灾难)。
ghg_ems$Country world$Country 存在多大的重合 ? 我们可使用 %in%
作符查看下,该操作符可查看一个向量有多少元素与另外一个向量匹配。本
例中就是查清 ghg_ems 中有多少国家(不重复)的名字出现在 world ...
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