lundi 30 avril 2018

If statement as vector/subsetting in R

I have two datasets, example of those given below.

DF1
Level
 10
 20
 10
 34

DF2
LevelLow     LevelHigh    Speed
   0            10          24
   11           20          29
   21           30          31
   31           40          36

I want to be able to add a column in DF1 which holds the speed of the Level if it's between the LevelLow and LevelHigh boundary. An example of the final dataset (DF1) is given below.

DF1
Level    Speed
 10        24
 20        29
 10        24
 34        36

I think I know how to do this via an if statement but how would I go about doing this in another way? I believe that vectorisation speeds up the process? If any of you know of any other way to do this then please let me know :)

Aucun commentaire:

Enregistrer un commentaire