lundi 5 janvier 2015

Check for consecutive years of giving in R

I work at a non-profit organization, and somebody wants a list of people who have given $100 or more in a 5-year span. The span can be anywhere, as long as they have given in 5 consecutive years. I have both Python and R on the computer. R seems like it would be better for this, but I'm not very familiar with it.


I've imported a csv file of every gift to the organization and who gave it.


Here is an example line from the csv file.



  • Gf_Gift_ID: 1620192

  • Gf_Date: 1/31/2005

  • Gf_Amount: 25.00

  • Gf_CnBio_ID: 512994


I couldn't get it to format correctly on here. The first part is the headers.


I need to be able to see if user 512994 has given 100 or more in, for example, 2014, 2013, 2012, 2011, and 2010 (five consecutive years).


So far I have this in the R script:



gifts <- read.csv("---------")
donors <- gifts["Gf_CnBio_ID"]
donors <- unique(donors)


I keep trying to figure out how to make a smaller dataframe that is a subset of gifts, by going one at a time through donors to subset gifts, and then I'd check to see how many years in a row that person has given. I keep getting errors the different ways I've tried it.


Thanks in advance. Most of my background is in Java so this language is not what I'm used to.


Aucun commentaire:

Enregistrer un commentaire