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 (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 ! Thanks for any suggestions/starting point Christian Schulz 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Renault, really thanks ! (2.problem) example: id filterCriteria ratingOfSatisfaction ProductType 1 Man 1 60 A 1 40 B 3 Women 3 20 A 5 Man 5 40 A 5 100 B 5 80 C I know that's no a perfect database model . But the dataset is much longer and now i have got a problem i.e filter the ratingOfSatisfaction with gender! Is there a possibilty to write a function in the really flexible R , which autocount (copy the rows under the first row per ID for the filterCriteria) until a new Id starts and again .... Thanks for advance & regards,Christian -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 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 5If I understand what you are looking for: tapply(c.row,id, length)> (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 ! > > Thanks for any suggestions/starting point > Christian Schulz > > > > > > 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 -- Readhttp://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 >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
....many thanks - this would be a big step for advanced learning in prg. R Christian Renaud Lancelot wrote:>>(2.problem) example: >>id filterCriteria ratingOfSatisfaction ProductType >>1 Man >>1 60 A >>1 40 B >>3 Women >>3 20 A >>5 Man >>5 40 A >>5 100 B >>5 80 C >> >>I know that's no a perfect database model . >> > >Sure ! > >>But the dataset is much longer and now i have got a problem >>i.e filter the ratingOfSatisfaction with gender! >> >>Is there a possibilty to write a function in the really flexible R , which >>autocount (copy the rows under the first row per ID for the filterCriteria) >>until a new Id starts and again .... >> > >The following assumes the file is perfect (no missing value). However, >you will get an idea of what is possible to do. I have copied and pasted >the example above in a file called "file.txt": > >>ProcessFile <- function(file){ >> >+ Line <- readLines(file) >+ Line <- tapply(X = seq(along = Line), >+ INDEX = seq(along = Line), >+ FUN = function(x, Line){ >+ vec <- unlist(strsplit(x = Line[x], split = " ")) >+ vec <- vec[vec != ""] >+ vec}, Line) >+ i <- 2; j <- 0 >+ List <- list() >+ while(i < length(Line)){ >+ xid <- Line[[i]][1] >+ xCrit <- Line[[i]][2] >+ i <- i + 1 >+ while(Line[[i]][1] == xid & i < length(Line)){ >+ j <- j + 1 >+ List[[j]] <- data.frame(id = xid, Crit = xCrit, >+ Sat = as.numeric(Line[[i]][2]), Type = Line[[i]][3]) >+ i <- i + 1 >+ } >+ } >+ do.call("rbind", List) >+ } > >>test <- ProcessFile(file = "d:\\analyses\\travail\\file.txt") >>test >> > id Crit Sat Type >1 1 Man 60 A >11 1 Man 40 B >12 3 Women 20 A >13 5 Man 40 A >14 5 Man 100 B >15 5 Man 80 C > >Then: > >>tapply(test$Sat, test$Crit, mean) >> > Man Women > 64 20 > >>tapply(X = test$Sat, test$Crit, table) >> >$Man > > 40 60 80 100 > 2 1 1 1 > >$Women > >20 > 1 > >>tapply(as.factor(test$Sat), test$Crit, table) >> >$Man > > 20 40 60 80 100 > 0 2 1 1 1 > >$Women > > 20 40 60 80 100 > 1 0 0 0 0 > >etc. > >Hope this helps, > >Renaud > >-------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20020528/944d8d54/attachment.html
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 5I 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 SchulzI 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._