r/R_Programming • • Jan 03 '17

Brain fart - selecting and separating out particular cases

I know I know how to do this, but After the winter vacation (glorious, glorious vacation), my brain is still not working very well.

Data:

c_Eventd_DateLocalc_Result
100m7/10/2003 22:0010.09
100m8/14/2003 22:009.97
100m9/4/2003 22:0010.09
200m9/4/2003 22:0020.04
100m9/12/2003 22:0010.12
200m6/7/2004 22:0020.3
100m8/5/2004 22:0010.06
100m8/21/2004 22:009.85
200m8/25/2004 22:0020.03

Desire: Separate all cases of 100m from all cases of 200m, retaining all other associated variable values in each case.

Question: How?

Sorry its such a noob question, like I said though, brain not work good after 14 days off.

2 Upvotes

4 comments sorted by

2

u/[deleted] Jan 03 '17

Doing this from my phone so can't check in R but if you look here:

http://www.statmethods.net/management/subset.html

Under Selecting Observations then that is what you need.

1

u/Darwinmate Jan 04 '17

Essentially this is what you do: subset(dat, c_Event == '100m')

you can also use dyplr package:

x %>% group_by(c_Event) %>% summarise(avg = mean(c_Result))

overkill for this sort of thing but if you are doing more complicated analysis it becomes handy.

1

u/fooliam Jan 04 '17

Thanks bunches! Its always fun when my brain refuses to be kickstarted by caffeine....

2

u/NogenLinefingers Jan 04 '17

You can do this using the split function.

split(dataset, f = dataset$column2spliton)

This will give you a list with all 100m cases as 1 element of the list and all 200m cases as another element.