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 版)
数据结构
155
数据框中的因子
创建数据框和创建 tibble 之间存在重要差异。使用 data.frame 函数创建数据框时,R
在默认情况下会将字符值转换为因子。前面的 data.frame 示例中的 pred3 值被转换
为一个因子,但这在输出中并不明显。
但是,tibble as_tibble 函数不会更改字符数据。如果你看一下 tibble 示例,
你会看到列 p3 的类型是 chr,意思是字符。
这种差异是你应该注意的。调试由这种细微差别引起的问题可能令人沮丧。
5.19 用行数据初始化数据框
5.19.1 问题
数据已经组织成行,而你需要将它们组合成一个数据框。
5.19.2 解决方案
将每一行数据存储在一个单行数据框中。然后使用 rbind 将多行结合到一个大型数据
框中:
rbind(
row1
,
row2
, ... ,
rowN
)
5.19.3 讨论
数据通常以一组观测结果的形式出现。每个观测(observation)都是一个包含多个值的
记录或元组,每个值代表一个观测变量。一个平面文件的行通常是这样的:每一行是一
条记录,每条记录包含多列,每列代表一个不同的变量(参见 4.15 节)。这些数据是以
观测
而非
变量
来组织的。换句话说,你一次只能获得一行而不是一列。
每个这样的行可能会以多种方式存储。一种显而易见的方式是把它存储为向量。如果有
纯粹的数值型(numerical)数据,可以用向量存储。
但是,许多数据集是数值、字符和分类数据的混合,在这种情况下,向量将不起作用。
我们建议将每个这样的异构行存储在一个单行数据框中。 ...
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