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 版)
简单编程
457
条件执行
R 语法包括 if 语句。有关详细信息,请参阅 help(Control)
循环
R 语法还包括 for 环、while 循环和 repeat 循环。有关详细信息,请参阅
help(Control)
Case switch 语句
一个名为 switch 的特殊函数提供了一个基本的 case 语句。然而,语法可能会让
你感到奇怪。有关详细信息,请参阅 help(switch)
惰性求值(lazy evaluation
调用函数时,R 不会立即计算函数参数。相反,它等待直到参数实际在函数内使用,
然后才进行求值。这为语言提供了特别丰富和强大的语义。大多数情况下,它并不
被注意,但偶尔会导致仅仅熟悉“即时求值”程序员的困惑,其中“即时求值”情
况下,函数参数在函数被调用时进行求值。
函数化编程
函数是“一等公民”,可以像其他对象一样对待:赋值给变量、传递给函数、被打印、
被检查等。
面向对象
R 支持面向对象的编程。事实上,面向对象有几种不同的范式,如果你喜欢有多种
选择,那么这是一种福音,如果你不喜欢,那就是令人困惑的。
15.1 在两种可能情况中进行选择:
if/else
15.1.1 问题
需要编写一个
条件分支
,它将根据简单的测试在两个路径之间进行选择。
15.1.2 解决方案
if 代码块可以通过测试一个简单的条件来实现条件逻辑:
if (
condition
) {
## do this if condition is TRUE
} else {
## do this if condition ...
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