jeudi 2 août 2018

Subsetting Data - more difficult than usual

I have a dataset that contains observations from different years. The observation did not start for all in the same year, meaning for example that some start in year 1996 and some start in 2008.

Element 1 | 4.1 | 2018

Element 1 | 3.9 | 2017

Element 1 | 3.4 | 2016

..........|.....| ....

Element 1 | 2.1 | 1996

Element 2 | 2.1 | 2018

Element 2 | 1.0 | 2017

..........|.....| ....

Element 2 | 1.0 | 2008

Now, I want to have a list that contains only observations which start from 2006 on. This means that this list would contain element 1 but not element 2.

My first approach was to use the command

subset(mydata, year > 2006)

but this did not work since it includes element 2 as it starts in 2008. I am stuck here. I want to tell R to subset the data only if the condition that the element was observed in years 2006 till 2018 is fulfilled. How should I approach this?

Aucun commentaire:

Enregistrer un commentaire