[R] Function, that assigns two vectors to each other

John Kane jrkrideau at inbox.com
Wed Jul 24 14:47:26 CEST 2013


Welcome  to R-help
it is a bit hard to see exactly what you want without data. Rest of the explanation looks good though it appears you may have sent this in HTML and the list asks for text.  It strips out the html and we lose any html format.

Can I suggest reading these https://github.com/hadley/devtools/wiki/Reproducibility
 http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example 

and then getting back to use with some data.  The best way to provide data , as is described in the above links is to use dput()  (type ?dput for help ) and then just copy and paste the results into the mail.



John Kane
Kingston ON Canada


> -----Original Message-----
> From: gallrein at psychologie.tu-dresden.de
> Sent: Wed, 24 Jul 2013 12:25:35 +0200
> To: r-help at r-project.org
> Subject: [R] Function, that assigns two vectors to each other
> 
> Hey guys,
> 
> In my data setv ("KD") I have 4 columns
> ("Punkte.AG1","Punkte.AG2","Punkte.AG3","Punkte.WI") I'm interested in.
> 
> These columns contain the participants' scores of a specific task.
> 
> I computed the percentiles of the columns using this code:
> 
> pe<-apply(X=KD[,c("Punkte.AG1","Punkte.AG2","Punkte.AG3","Punkte.WI")],
> 
> MARGIN=2,
> 
> FUN=quantile,
> 
> probs=seq(0,1,by=.01),
> 
> na.rm=TRUE)
> 
> round(pe,0)
> 
> 
> This is the output (to the 20^th percentile):
> 
> pe
> 
> Punkte.AG1 Punkte.AG2 Punkte.AG3 Punkte.WI
> 
> 0%6319
> 
> 1%74311
> 
> 2%86312
> 
> 3%87412
> 
> 4%97512
> 
> 5%98512
> 
> 6%108512
> 
> 7%108512
> 
> 8%108614
> 
> 9%109614
> 
> 10%109615
> 
> 11%1010715
> 
> 12%1010715
> 
> 13%1110715
> 
> 14%1110816
> 
> 15%1110816
> 
> 16%1110816
> 
> 17%1110816
> 
> 18%1110816
> 
> 19%1210816
> 
> 20%1210816
> 
> So now I know, what percentile a person has, when she/ he scored a
> certain amount of points (e.g. 6 points in "Punkte.AG1" = 0%).
> 
> Here is my problem:
> 
> I now want to write a function that assigns the percentile to the score
> (for each task) and saves it in a new variable.
> 
> So every person that scored 10 in "Punkte.AG1" gets a "12" in the new
> variable "Percentile.AG1".
> 
> Every person that scored 6 in "Punkte.AG1" gets a "6" in the new
> variable "Percentile.AG1".
> 
> The same thing should be done for the other tasks.
> 
> 
> I new to R, so I don't have any clue, how to solve that. It would be
> awesome, if you would know how to handle that.
> 
> Thanks a lot!
> 
> Anne
> 
> --
> M. Sc. Anne-Marie B. Gallrein
> Technische Universitdt Dresden
> Institut f|r Klinische, Diagnostische und Differentielle Psychologie
> Diagnostik und Intervention
> 01062 Dresden
> Tel. +49 351 463-34004
> gallrein at psychologie.tu-dresden.de
> 
> 
> 	[[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.

____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails



More information about the R-help mailing list