3
1

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のデータフレーム の任意の行に任意の要素が含まれているか否かの判定方法

Posted at

概要

Rを使っていた時に,Pythonのように

要素 in list

の形では,要素が含まれているか否かを判定できず,またそれに完全に合致するポストがなかったので解決策をポストします.
なお,Rの型の理解が今ひとつなので,間違っていたらご指摘をいただけますと幸いです.

環境

R==3.4.2

コード

> a = data.frame(V1=c('abcd','efgh','ijkl'))
> a
    V1
1 abcd
2 efgh
3 ijkl
> 'abcd' %in% a$V1
[1] TRUE
> 'abc' %in% a$V1
[1] FALSE

これだけ.inではなくて,%in%を使えばいいらしい.

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?