Skip to Content
Rクックブック 第2版
book

Rクックブック 第2版

by J.D. Long, Paul Teetor, 大橋 真也, 木下 哲也
January 2020
Intermediate to advanced
584 pages
7h 18m
Japanese
O'Reilly Japan, Inc.
Content preview from Rクックブック 第2版

12章便利なテクニック

本章のレシピは、わかりにくい数値計算や難しい統計学的手法ではなく、頻繁に必要となる便利な関数や、よく使われるテクニックです。

レシピ12.1 データの一部を表示する

問題

データが多すぎて一度には表示できない。データの一部を確認したい。

解決策

headを使うと、データの最初の数行を表示できます。

head(x)

tailを使うと、データの最後の数行を表示できます。

tail(x)

または、RStudioのインタラクティブビューアで全体を表示することもできます。

View(x)

解説

大量のデータセットを出力しても、すべてが画面上を流れて行ってしまうだけで意味がありません。headを使うと、データの一部が表示できます(デフォルトでは6行)。

load(file = './data/lab_df.rdata')
head(lab_df)
##         x lab      y
## 1  0.0761  NJ  1.621
## 2  1.4149  KY 10.338
## 3  2.5176  KY 14.284
## 4 -0.3043  KY  0.599
## 5  2.3916  KY 13.091
## 6  2.0602  NJ 16.321

tailを使うと、最後の数行とその行番号が表示できます。

tail(lab_df)
##          x lab      y
## 195  7.353  KY 38.880
## 196 -0.742  KY -0.298
## 197  2.116  NJ 11.629
## 198  1.606  KY  9.408
## 199 -0.523  KY -1.089
## 200  0.675  KY  5.808

headtailは、どちらも数値を渡して返す行を指定できます。 ...

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クイックリファレンス 第2版

Rクイックリファレンス 第2版

Joseph Adler, 大橋 真也, 木下 哲也
ハイパフォーマンスPython 第2版

ハイパフォーマンスPython 第2版

Micha Gorelick, Ian Ozsvald, 中山 光樹
Rではじめるデータサイエンス 第2版

Rではじめるデータサイエンス 第2版

Hadley Wickham, Mine Çetinkaya-Rundel, Garrett Grolemund, 大橋 真也
Rではじめるデータサイエンス

Rではじめるデータサイエンス

Hadley Wickham, Garrett Grolemund, 黒川 利明, 大橋 真也

Publisher Resources

ISBN: 9784873118857Other