This looks like homework. Please read the Posting Guide mentioned at the end of
every posting regarding homework.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Tabby <dj.lan296 at gmail.com> wrote:
>I need help writing function that takes three categorical inputs and
>returns
>a vector of summary statistics based on these inputs. The data set
>contains
>information on retail goods that can be specified by their retail
>segment,
>brand name, and type of good along with its retail price and what it
>actually sold for. I need to write a function that will take these
>inputs
>and average, count, and calculate whatever else is needed.
>
>I have set the function up as follows (using made up data):
>
>dataold=data.frame(segment=c("golf","tenis","football","tenis","golf","golf"),
>brand=c("x","y","z","y","x","a"),type=c("iron","ball","helmet","shoe","driver","iron"),
>retail=c(124,.60,80,75,150,108),actual=c(112,.60,72,75,135,100))
>
>retailsum=funtion(segment,brand,type){
>
>datanew=dataold[which(dataoldsegment='segment' &
dataoldbrand='brand' &
>dataold$type='type'),c("retail","actaul")]
>
>summary=c(dim(datanew)[1],colMeans(datanew)) return(summary) }
>
>The code inside the function braces works on its own, but once I wrap a
>function around it I start getting errors or it will just return 0
>counts
>and NaN for the means.
>
>Any help would be greatly appreciated. I have very little experience in
>r,
>so I apologize if this is a trivial question, but I have not been able
>to
>find a solution.
>
>Thank you, D
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Help-writing-function-in-R-tp4629824.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>R-help at 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.