Hi Roslina, Try this: aggbalok_mth[aggbalok_mth$year %in% 2009:2014,]
Jim On Fri, Jul 29, 2016 at 1:12 PM, roslinazairimah zakaria <roslina...@gmail.com> wrote: > Dear r-users, > > I would like to extract year from 2009 to 2014 with the corresponding month > and rain amount. > > I tried this: > aggbalok_mth[aggbalok_mth$year == 2009:2014, ] but some of the data is > missing. > >> dput(aggbalok_mth[aggbalok_mth$year == 2009:2014, ] ) > structure(list(month = c(1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12 > ), year = c(2009, 2009, 2010, 2010, 2011, 2011, 2012, 2012, 2013, > 2013, 2014, 2014), x = c(424.6, 59.5, 6, 54.6, 387.9, 236.1, > 160.3, 162.5, 102.8, 139.5, 293.3, 39)), .Names = c("month", > "year", "x"), row.names = c(7L, 13L, 20L, 26L, 33L, 39L, 46L, > 52L, 59L, 65L, 72L, 78L), class = "data.frame") > Warning message: > In aggbalok_mth$year == 2009:2014 : > longer object length is not a multiple of shorter object length > > > Here is the my data: > > structure(list(month = c(7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, > 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, > 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, > 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, > 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, > 11), year = c(2008, 2008, 2008, 2008, 2008, 2008, 2009, 2009, > 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2010, > 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, > 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, > 2011, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, > 2012, 2012, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, > 2013, 2013, 2013, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, > 2014, 2014, 2014, 2014, 2015, 2015, 2015, 2015, 2015, 2015, 2015, > 2015, 2015, 2015, 2015), x = c(0, 168.7, 203, 149.3, 299.9, 570.7, > 424.6, 52.6, 407.7, 210.3, 459.8, 249.2, 59.5, 310.4, 182.7, > 433.3, 161, 560.5, 197.5, 6, 68.9, 170.4, 117, 271.2, 133.5, > 54.6, 145.5, 122.5, 460.9, 708, 646.7, 58.8, 387.9, 42.9, 190.7, > 133.3, 131.7, 158.4, 236.1, 412.9, 462.5, 713.8, 437.1, 140.1, > 311.4, 160.3, 202.4, 58.8, 134.7, 120.4, 206.9, 162.5, 68.5, > 1025.9, 229.5, 331, 9, 51.4, 102.8, 162.9, 157.2, 32.6, 103.9, > 158.7, 139.5, 1371.2, 221.5, 6.1, 19.1, 11, 87.7, 293.3, 87.3, > 184, 69.5, 231, 448.2, 39, 19.3, 3.9, 53.8, 141.9, 325, 53.5, > 133.3, 321.1, 77.6, 156.5, 2.2)), .Names = c("month", "year", > "x"), row.names = c(NA, -89L), class = "data.frame") > > Thank you very much for any help given. > -- > *Dr. Roslinazairimah Binti Zakaria* > *Tel: +609-5492370; Fax. No.+609-5492766* > > *Email: roslinazairi...@ump.edu.my <roslinazairi...@ump.edu.my>; > roslina...@gmail.com <roslina...@gmail.com>* > Deputy Dean (Academic & Student Affairs) > Faculty of Industrial Sciences & Technology > University Malaysia Pahang > Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.