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 > データ構造 > データフレーム > 特定の部分だけ変更する実装

Last updated at Posted at 2016-09-22
動作環境
RStudio 0.99.903 on Windows 7 pro
R version 3.3.1

R機能マップ http://qiita.com/7of9/items/0f911bcb95d3a8bbd703

データフレームの一部の値を変更してみる。
変更箇所は以下

  • 2列2行目
  • 2列3行目
  • 3列2行目
  • 3列3行目
> x<-data.frame(V1=c(1,0,0),V2=c(0,2,2),V3=c(0,2,1))
> x
  V1 V2 V3
1  1  0  0
2  0  2  2
3  0  2  1

上記で作ったデータフレームを変更する。

> x[2:3,2:3]=data.frame(V1=c(1,1),V2=c(1,1))
> x
  V1 V2 V3
1  1  0  0
2  0  1  1
3  0  1  1
  • 左側の[ , ]に変更したい位置を指定
  • 右側のframe()内に値を指定
    • 2列なのでV1, V2とする
> x[1:1,2:3]=data.frame(V1=c(3),V2=c(3))
> x
  V1 V2 V3
1  1  3  3
2  0  1  1
3  0  1  1
  • 左側の[ , ]の指定は最初が「行」で次が「列」のようだ
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?