0
0

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 > "1,2,3,4,5,6"というファイルから指定の列を抜出す > x[c(2,4,6)] / x[c(seq(2,6,2))]

Last updated at Posted at 2016-09-19
動作環境
RStudio 0.99.903 on Windows 7 pro
R version 3.3.1
column.txt
1,2,3,4,5,6

上記のようなファイルから列を指定して取り出す方法。

> setwd("d:/TestData/160911_R/")
> x<-read.table("column.txt",sep=",")
> head(x)
  V1 V2 V3 V4 V5 V6
1  1  2  3  4  5  6

c()を使って指定の列を取出す。

> x[c(2,4,6)]
  V2 V4 V6
1  2  4  6

seq()を組み合わせてもいい。

> x[c(seq(2,6,2))]
  V2 V4 V6
1  2  4  6
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?