[R] how to quote "factors" in a function?

R. Michael Weylandt <michael.weylandt@gmail.com> michael.weylandt at gmail.com
Mon Sep 12 01:48:27 CEST 2011


You quote them in quotes. "A"

Also: bad scoping. 

Michael Weylandt

On Sep 11, 2011, at 6:11 PM, casperyc <casperyc at hotmail.co.uk> wrote:

> ### code ###
>    x=sample(LETTERS[1:26],100,T)
>    prob=function(y){
>            count=sum(x==y)
>            total=length(x)
>            count/total
>    }
> ### end ###
> 
> How do I quote the letters A,B,C,D ect, in order to make the "prob" function
> return the weights of the desired Letter?
> 
> Thanks!
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-quote-factors-in-a-function-tp3805913p3805913.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.



More information about the R-help mailing list