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 版)
统计概论
227
mean(diff(ts)> 0)
时间序列中大于前一个观测值的观测值所占的比例
9.3 因子数据的表格和列联表创建
9.3.1 问题
你需要将一个因子呈现为表格或根据多个因子构建列联表。
9.3.2 解决方案
函数 table 产生一个因子的计数:
table(f1)
#> f1
#> a b c d e
#> 14 23 24 21 18
它还可以根据两个或多个因子生成列联表(交叉表):
table(f1, f2)
#> f2
#> f1 f g h
#> a 6 4 4
#> b 7 9 7
#> c 4 11 9
#> d 7 8 6
#> e 5 10 3
9.3.3 讨论
函数 table 也适用于字符串,而不仅仅是因子:
t1 <- sample(letters[9:11], 100, replace = TRUE)
table(t1)
#> t1
#> i j k
#> 20 40 40
函数 table 计算一个或多个因子的水平,例如因子 initial 和因子 outcome 的水平计数:
set.seed(42)
initial <- factor(sample(c("Yes", "No", "Maybe"), 100, replace =
TRUE))
outcome <- factor(sample(c("Pass", "Fail"), 100, replace = TRUE))
table(initial)
#> initial
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

Istio 学习指南

Istio 学习指南

Lee Calcote, Zack Butcher
数据压缩入门

数据压缩入门

Colt McAnlis, Aleks Haecky
Python数据处理

Python数据处理

Jacqueline Kazil, Katharine Jarmul

Publisher Resources

ISBN: 9787111656814