R code example to extract a subset of data

> a=seq(10,1,by=-1)
> b=seq(1,10)
> dat=cbind(a,b)
> dat
       a  b
 [1,] 10  1
 [2,]  9  2
 [3,]  8  3
 [4,]  7  4
 [5,]  6  5
 [6,]  5  6
 [7,]  4  7
 [8,]  3  8
 [9,]  2  9
[10,]  1 10
> c=c(4,2,8,5)
> c
[1] 4 2 8 5
> dat[a%in%c,]
     a b
[1,] 8 3
[2,] 5 6
[3,] 4 7
[4,] 2 9

About Hongwei Xu

I'm a social demographer, a single-child, a husband, and a father.
This entry was posted in Research. Bookmark the permalink.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s