0

I would like to fill a column with localisation information (flight / perched / feeding) dependent on the time.

For example, from 13:16:11 to 13:18:32 I know that the bird is flying so I want to put "flight" on the localization column for this period, someone can help me ?

For now, I created a empty column but now I don't know how to fill it.

Thanks, Manon

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Is there only 1 bird in your dataframe? You can specify what you want to add to the empty column (here I've called it 'localisation') using the square brackets [], which are used for sub setting. I haven't dealt with time in R for a while, but I think this should work.

df$localisation[df$time >= "13:16:11" & df$time <= "13:18:32",] <- "flight"

P_Ling
  • 37
  • 6
  • Yes I have only one bird for now ! – Manon Billard Mar 25 '20 at 10:11
  • Thanks you ! I tried your suggestion but I have : "Error in Data_comp$Localisation[Data_comp$UTC_datetime < ymd_hms("2020-02-18 13:18:32"), : incorrect number of clues on the matrix" – Manon Billard Mar 25 '20 at 10:57
  • Can you upload a sample dataset to your question? If you can I'll try the code and see if I can fix it. – P_Ling Mar 25 '20 at 22:00
  • I found a way to go through it, I used : Data_comp <- Data_comp %>% filter(UTC_datetime >= ymd_hms("2020-02-19 13:53:28") & UTC_datetime < ymd_hms("2020-02-19 13:53:59")) Data_comp$Localisation <- c("Flight") str(Data_comp) Thanks you very much :) – Manon Billard Apr 01 '20 at 15:14