[R] KS test and data format
Marc Schwartz
mschwartz at medanalytics.com
Sun Jun 23 03:49:56 CEST 2002
> Dear All,
>
> I've a problem with the data format and the ks.test() function
> (Kolmogorov-Smirnov). The test function expects two numeric vectors,
but
> the two data distributions I'd like to test are actually in the
> following format:
>
> 2 4
> 3 6
> 5 6
> 7 2
> ...
>
> where the 1st column is a data position and the 2nd is the frequency
> this data point is observed. To generate an appropiate vector I've to
> turn the frequencies into the actual numbers, like:
>
> 2
> 2
> 2
> 2
> 3
> 3
> 3
> 3
> 3
> 3
> ...
>
> I could write a C program for this, but I was wondering whether there
is
> a quick way in R to do this data transformation.
>
> thanks alot for help,
>
> Arne
Presuming that you have your data in R in the two column format that you
define above, which I'll call 'data', how about something like:
data.1 <- rep(data[, 1], data[, 2])
This tells R to replicate that value in column 1 (data[, 1]) by the
number in the column 2 (data[, 2]) and put the result in a vector called
'data.1'.
For more information do ?rep.
HTH.
Marc
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list