0

The data that I am trying to work with is in a data.frame that has the following format:

Title Year
Something 2006
something2 2007
Something 2008
Something 2009

I'm specifically interested in being able to subset the data so that their chronological order is fewer then 2008. For example, this would give:

Title Year
Something 2009

Is it acceptable to use something like this:

df[!(df$Year <= 2008), ]
coatless
  • 20,011
  • 13
  • 69
  • 84
Teres
  • 73
  • 1
  • 8
  • 1
    Yes, df$Year needs to be numeric, though. – aichao Oct 13 '16 at 12:13
  • 1
    Can you give a reproducible example? And the answer that you want. Please go through http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Kumar Manglam Oct 13 '16 at 12:20
  • Just a friendly tip, you may want to read over this page: The [How-To-Ask Guide](https://stackoverflow.com/help/how-to-ask) so you can always be sure that your questions are easily answerable and as clear as possible. Be sure to include any efforts you've made to fix the problem you're having, and what happened when you attempted those fixes. Also don't forget to your show code and any error messages! – Matt C Oct 13 '16 at 15:40
  • Seems like a yes/no question here. What exactly are you asking? – Rich Scriven Oct 15 '16 at 22:44

1 Answers1

0

If by fewer mean older (lower number) than you are looking for df<-df[df$Year>2008] or as you do df<-df[!df$Year<=2008]

You will need to overwrite the original data.frame, or it will just display the subset, but not save it. You can also use subset(df, Year>2008) or dplyr package. Whaever suits you best.

Jan Sila
  • 1,554
  • 3
  • 17
  • 36