I really need help altering a function I have written.  The function
currently performs a specific task on a dataframe.  I now wish to be able to
use it with a splitting function by either passing it a pre-split dataframe
or by being able to designate the splitting factor.

Can anyone advise?

Here is my function:

attrition<-function(x){
        atr.model<-matrix(nrow=8, ncol=2)
        rownames(atr.model)<-c("Report", "Submission", "Loading", "Link",
"C.P.Link", "C.P.Sub", "Clear", "Performance")
        
        #cases reported
        atr.model["Report", 1]<-Reported[nrow(Reported),2]
        atr.model["Report", 
2]<-(atr.model["Report",1]/atr.model["Report",1])*100
        
        #submission rate
        atr.model["Submission",1]<-nrow(x)
        atr.model["Submission", 2]<-(atr.model["Submission", 
1]/atr.model["Report",
1])*100
        
        #loading rate
        atr.model["Loading",1]<-sum(x$Loaded.=="Y", x$Loaded.=="PC", na.rm=T)
        atr.model["Loading", 2]<-(atr.model["Loading", 
1]/atr.model["Submission",
1])*100
        
        #link rate
        atr.model["Link",1]<-sum(x$Linked.=="Y", na.rm=T)
        atr.model["Link", 2]<-(atr.model["Link", 1]/atr.model["Loading", 1])*100
        
        #C.P
        atr.model["C.P.Link",1]<-sum(x$Link.Type=="C.P", x$Link.Type=="C.C.P",
na.rm=T)
        atr.model["C.P.Link", 2]<-(atr.model["C.P.Link", 1]/atr.model["Link",
1])*100
        
        #C.P/Sub
        atr.model["C.P.Sub", 2]<-(atr.model["C.P.Link", 
1]/atr.model["Submission",
1])*100
        
        #clear
        atr.model["Clear", 2]<-100
        
        #Performance
        atr.model["Performance",2]<-prod(atr.model["Submission", 2]/100,
atr.model["Loading", 2]/100, atr.model["C.P.Link", 2]/100,
atr.model["Clear", 2]/100)*100
        
        atr.model[,2]<-round(atr.model[,2], 1)
        
        print(atr.model)
        }

As you can see it works for a dataframe now.  However I wish to build in a
split function or have it be able to deal with a split dataframe in the form
of a list.

Any advise would be fantastic.

Thanks

Gareth Campbell
-- 
View this message in context: 
http://n4.nabble.com/Advice-get-my-function-to-work-with-a-list-tp955783p955783.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to