[R] Data indexing issue...
Ivan Calandra
ivan.calandra at u-bourgogne.fr
Tue Mar 27 13:43:09 CEST 2012
Hi HJ,
Take a look at ?"&"; this is probably what you're looking for.
What you could also do is:
Calender[Calender$Day=='Wd' & Calender$Season=="Winter", ] # notice the
last comma
This will subset directly without using which(); it might be helpful to you.
HTH,
Ivan
--
Ivan CALANDRA
Université de Bourgogne
UMR CNRS/uB 6282 Biogéosciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calandra at u-bourgogne.fr
http://biogeosciences.u-bourgogne.fr/calandra
Le 27/03/12 12:32, HJ YAN a écrit :
> Dear R-help,
>
> My dataset (which is a data frame, called 'Calender' here) includes 365
> rows representing 365 days for a year. One column ('Season')contains
> factor data representing seasons, e.g. spring, summer, autumn and winter.
> Another column (called 'Day') contains data representing wether the day is
> a working day (I use 'Wd' for short here)or weekend (I use 'Wkend' for
> short here).
>
>
> I want to seperate the index of the working days and weekends for each
> season. I used R commend "which" before for one criteria, for example, if I
> use...
>
>
> WdIndex<-which(Calender$Day=='Wd')
>
> that will gives a set of indeices of working days in the year.
>
> I wonder in R could I use a combination of something such as 'AND' , 'OR'
> (e.g. in MySQL) to set 'multi-criteria' when selecting data. So for
> example...
>
> WinterWdIndex<-which(Calender$Day=='Wd' AND Calender$Season=="Winter")
>
>
> I know the above syntax is wrong, and I checked '?which' which did not give
> me an answer and also tried '?AND' but seems it doesn`t exist at all...
>
>
> Many thanks!
> HJ
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
>
More information about the R-help
mailing list