Use of $ and %% operators in R -


i have been working r 2 months , have had little bit of trouble getting hold of how $ , %% terms.

i understand can use $ term pull value function (e.g. t.test(x)$p.value), i'm not sure if universal definition. know possible use specify pull data.

i'm curious use of %% term, in particular, if placing value in between (e.g. %x%) aware of using modulator or remainder e.g. 7 %% 5 returns 2. perhaps being ignorant , not real?

any or links literature appreciated.

note: have been searching couple hours excuse me if couldn't find it!

you not pulling value function rather list object function returns.

 t.test  # function  t.test(x) # named list 1 of names being "p.value" 

the value can pulled in 1 of 3 ways:

 t.test(x)$p.value  t.test[['p.value']]  # numeric vector  t.test['p.value']  # list 1 item   my.name.for.p.val <- 'p.value'  t.test(x)[[ my.name.for.p.val ]] 

when surround set of characters flanking "%"-signs can create own vectorized infix function. if wanted pmax defautl na.rm=true this:

 '%mypmax%' <- function(x,y) pmax(x,y, na.rm=true) 

and use without quotes:

> c(1:10, na) %mypmax% c(na,10:1)  [1]  1 10  9  8  7  6  7  8  9 10  1 

Comments