[R] id & filter problems in data.frame
Yves Brostaux
brostaux.y at fsagx.ac.be
Wed May 29 09:58:21 CEST 2002
Hello,
>Date: Tue, 28 May 2002 10:30:14 +0200
>From: Christian Schulz <c.schulz at metrinomics.de>
>Subject: [R] id & filter problems in data.frame
>
>Hi,
>a questionaire data-set with more than one row for one Person make
>me problems.
>
>(1) i want create a function which count the used
>row for the relevant id !
>example:
>id c.row
>1 1
>1 2
>1 3
>2 1
>2 2
>4 1
>4 2
>4 3
>4 4
>4 5
I think the following function should do the trick (obtaining c.row from id
if I understood well the problem) :
count <- function(id) {
temp <- tapply(id, id, function(x) {x <- rep(1, length(x)); cumsum(x)})
temp <- unlist(temp)
names(temp) <- NULL
return(temp)
}
> id <- rep(c(1, 2, 4), c(3, 2, 5))
> id
[1] 1 1 1 2 2 4 4 4 4 4
> c.row <- count(id)
> c.row
[1] 1 2 3 1 2 1 2 3 4 5
>(2) i have got a problem to filter & analyse , because the filter
>criteria is unlucky
>a row above or under the ratings which i would like to analyse !
I fear I don't understand what you want to do...
>Thanks for any suggestions/starting point
>Christian Schulz
I hope it helped a bit !
Y. Brostaux
>Metrinomics GmbH
>Fon: +49 (0)30 69 51 71 - 16
>Fax: +49 (0)30 69 51 71 - 33
>mailto:c.schulz at metrinomics.de
>http://www.metrinomics.de
>
>
>-
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>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
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
=====================================================================
YVES BROSTAUX - Ingénieur agronome Orientation Eaux & Forêts
Assistant - Unité de Statistique et Informatique
Gembloux Agricultural University
8, avenue de la Faculté B-5030 Gembloux (Belgium)
Tél: +32 (0)81 62 24 69
E-mail : brostaux.y at fsagx.ac.be
=====================================================================
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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