0

I would like to pick up only data in column x and x-date for each person. (in condition of x-date is between day1 and day2 columns for each person). Please see the picture below

For example,

a, x=111, x-date=2/2/2016
b, x=8990, x-dates=2/3/2016
c, x=333, x-dates=5/5/2011

image of data.frame

sKhan
  • 9,694
  • 16
  • 55
  • 53
Charles
  • 13
  • 4
  • 2
    My first suggestion would be to paste your data using `dput(df)` instead of using an image, see - http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – thelatemail Feb 16 '16 at 23:10
  • 1
    What have you done so far? And +1 on `dput(df)`; the structure of your data (e.g. the format of your dates) is relevant here. – alistaire Feb 16 '16 at 23:12

2 Answers2

0

If I got your question right, and if all your dates are in Date format, you could probably just do something like that :

Base R :

 df[(df$x-date > df$day1 & df$x-date < df$day2), c('person', 'x', 'x-date')]
Matthieu P.
  • 131
  • 4
0

you could use the subset function.

subset(df, x==111 & x-date=='2/2/2016', select = c(person,x,x-date))
Seekheart
  • 1,135
  • 7
  • 8