1. 程式人生 > >R語言從基礎入門到提高(三)Vectors(向量)

R語言從基礎入門到提高(三)Vectors(向量)

Working with comparisons will make your data analytical life easier. Instead of selecting a subset(子集) of days to investigate(研究) yourself (like before), you can simply ask R to return only those days where you realized a positive return for poker.

In the previous exercises you used selection_vector <- poker_vector > 0

 to find the days on which you had a positive poker return. Now, you would like to know not only the days on which you won, but also how much you won on those days.

You can select the desired(渴望的) elements, by putting selection_vectorbetween the square brackets that follow poker_vector:

poker_vector[selection_vector]
R knows what to do when you pass a logical vector in square brackets: it will only select the elements that correspond to(對應是) TRUE in selection_vector.