Here you go Uri. This should help you out.
I wanted to create a list of all the claims per each member id. So, I wrote a function that accepts a data.table and a vector of the unique member ID's as inputs. Here is the function:
CreateListOfMemberClaims <- function(dt, ids) {
##
# FUNCTION NAME: CreateListOfMemberClaims
# INPUTS: dt = A data.table of the claims for a particular year
# ids = The member id's to look for
#
# OUTPUTS: memberList = list of all the claims as a data.frame for each member id.
##
memberList <- list()
for(i in 1:length(ids)) {
memberList[[i]] <- data.frame(dt[J(ids[i])])
}
return(memberList)
}
Here's how you use the function: Notice that I have converted only the data.frame for Y1 claims into a data.table. I called this new
data.table qq for lack of a better name. Now you need to specify what the key of this table is. I chose MemberID as the key.
library(data.table)
qq <- data.table(claims[which(claims$Year == "Y1"), ])
setkey(qq, MemberID)
#now use the function. You need the data.table and a vector of all the unique ID's
t1 <- which(claims$Year == "Y1")
uniqueVectorOfIDs <- unique(claims$MemberID[locYXList[[1]]])
y1MemberList <- CreateListOfMemberClaims(qq, uniqueVectorOfIDs)
# For all this to work, simply copy paste the function from above into R, make sure you install the package data.table and then copy paste the
rest of the code. In order to install the package you can type install.packages("data.table") It's a two step process..First you install a package, then you load it by
typing either library(packageName) or require(packageName)
with —