Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular assignment in R

Tags:

r

I found a line the the genetics package that goes like this:

P <- D <- Dprime <- nobs <- chisq <- p.value <- corr <- R.2 <- P

note P is both at the beginning and at the end. What does it mean?

like image 588
qed Avatar asked May 10 '13 15:05

qed


1 Answers

This construct will assign the value of P to variables with each of the other names given in the string of <-s. That assignment will take place in the current environment.

Thus, if the variable named P on the far right is not in the current environment, a new variable P will be created in the current environment.

To see this in action, run the following from a fresh R session:

ls()
# character(0)
mean <- a <- b <- mean
ls()
# [1] "a"    "b"    "mean"
like image 116
Josh O'Brien Avatar answered Oct 08 '22 00:10

Josh O'Brien