lundi 7 août 2017

R- Help me add values with same date

I have a data set named pnc_1

It has the date column with several repeating dates and the wid column with numeric values . I am trying to add up all the wid values for each identical date and then put the results into a vector. Here is what I have. This loop freezes R-Studio.

cumsum <- 0
for (i in 1:(nrow(pnc_1)-1)) {
  while (pnc_1$date[i] == pnc_1$date[i+1]) {
    cumsum <- (pnc_1$wid[i] + pnc_1$wid[i+1])
  }
}

Help please.

Aucun commentaire:

Enregistrer un commentaire