[R] Application of "merge" and "within"
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Sat May 28 22:20:36 CEST 2016
Why do you want to do this?
--
Sent from my phone. Please excuse my brevity.
On May 27, 2016 4:00:14 PM PDT, Santosh <santosh2005 at gmail.com> wrote:
>Dear Rxperts!
>
>Is there a way to compute relative values.. using within().. function?
>
>Any assistance/suggestions are highly welcome!!
>Thanks again,
>Santosh...
>___________________________________________________________________
>A sample dataset and the computation "outside" within() function is
>shown..
>
>q <- data.frame(GL = rep(paste("G",1:3,sep = ""),each = 50),
> G = rep(1:3,each = 50),
> D = rep(paste("D",1:5,sep = ""),each = 30),
> a = rep(1:15,each = 10),
> t = rep(seq(10),15),
> b = round(runif(150,10,20)))
>r <- subset(q,!duplicated(paste(G,a)),sel=c(G,a,b))
>names(r)[3] <- "bl"
>s <- merge(q,r)
> s$db <- s$b-s$bl
>
>> head(s,5)
> G a GL D t b bl db
>1 1 1 G1 D1 1 13 13 0
>2 1 1 G1 D1 2 16 13 3
>3 1 1 G1 D1 3 19 13 6
>4 1 1 G1 D1 4 12 13 -1
>5 1 1 G1 D1 5 19 13 6
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.
[[alternative HTML version deleted]]
More information about the R-help
mailing list