[R] Odp: Re : table function

Petr PIKAL petr.pikal at precheza.cz
Tue Aug 25 11:15:23 CEST 2009


Hi

r-help-bounces at r-project.org napsal dne 25.08.2009 10:08:36:

> Hi Mark,
> 
> 
> Thank you for your answer !! it works but if i have "NA" in the vector z 
what 
> i shoud do to count its number in Z?

You do not have NA in z, you manage to convert it somehow to factor. 
Please try to read about data types and its behaviour. Start with this 
chapter
2.8 Other types of objects
in R intro manual which I suppose you have in doc folder of R program 
directory. You possibly can convert it back to numeric by

e.g.

DF$z <- as.numeric(as.character(DF$z))

but I presume you need to check your original data maybe by

str(your.data) what mode they are and why they are factor if you expect 
them numeric.

Regards
Petr

> x      y        z
> > 1    0      100
> > 5    1      1500
> > 6    1      NA
> > 2    2      500
> > 1    1      NA
> > 5    2    2000
> > 8    5    4500
> > 
> 
> i did the same but it gives me this error  message:
>  [0 - 1000] [1000 - 3000]         >3000 
>             0             0             0 
> Warning message:
> In inherits(x, "factor") : NAs introduced by coercion
> 
> 
> Thank you 
> 
> 
> ________________________________
> De : Marc Schwartz <marc_schwartz at me.com>
> 
> Cc : r-help at r-project.org
> Envoyé le : Lundi, 24 Aoűt 2009, 18h33mn 52s
> Objet : Re: [R] table function
> 
> On Aug 24, 2009, at 10:59 AM, Inchallah Yarab wrote:
> 
> > hi,
> > 
> > i want to use the function table to build a table not of frequence 
(number 
> of time the vareable is repeated in a list or a data frame!!) but in 
function of classes
> [[elided Yahoo spam]]
> > 
> > example
> > 
> > x      y        z
> > 1    0      100
> > 5    1      1500
> > 6    1      1200
> > 2    2      500
> > 1    1      3500
> > 5    2    2000
> > 8    5    4500
> > 
> > i want to do a table summerizing the number of variable where z is in 
> [0-1000],],[1000-3000], [> 3000]
> > 
> > thank you very much for your help
> 
> 
> See ?cut, which bins a continuous variable.
> 
> > DF
>   x y    z
> 1 1 0  100
> 2 5 1 1500
> 3 6 1 1200
> 4 2 2  500
> 5 1 1 3500
> 6 5 2 2000
> 7 8 5 4500
> 
> 
> > table(cut(DF$z, breaks = c(-Inf, 1000, 3000, Inf),
>             labels = c("0 - 1000", ">1000 - 3000", ">3000")))
> 
>     0 - 1000 >1000 - 3000        >3000
>           2            3            2
> 
> HTH,
> 
> Marc Schwartz
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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