11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rの data frame から行や列を選択して取り出す

Last updated at Posted at 2013-10-11

data がデータフレームだとして

# 最初の5行取り出す
data[1:5, ]
# 最初の100列取り出す
data[, 1:100]
# 最初の5行100列を取り出す
data[1:5, 1:100]

行をランダムサンプリングする場合は、サンプリングする行を sample() 関数で作り、インデックス指定で取り出す。

ランダムに100行取り出す。

data[sample(nrow(data), 100),]
11
13
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?