http://stat.ethz.ch/R-manual/R-patch...l/matmult.html
It is called "matrix multiplication"/"inner product"
(Not a R expert)
I am determined to learn more about the nuts and bolts of R syntax so I plan to keep asking questions until I get it right!
often I see percentage symbols in lines of code, but rarely stop to ask what is this doing exactly. Can some please explain to me what they are doing
For example, trinker posted this recently:
What is %*% doing and how do you read it?Code:#DOING THE MATRIX MULTIPLICATION (b <- Min %*% Xp) #The upper is the intercept and the lower is the slope #.............................................. SUM #compare to b
The earth is round: P<0.05
http://stat.ethz.ch/R-manual/R-patch...l/matmult.html
It is called "matrix multiplication"/"inner product"
(Not a R expert)
Thankyou BGM
The earth is round: P<0.05
In general whenever you see the syntax %something_here% <--- that whole thing is a binary operator. You can actually define your own binary operators with this syntax
Code:> # Make a binary operator that adds the two numbers together and then subtracts two > "%mwa%" <- function(x, y){ #has to take two and only two parameters + (x + y) - 2 + } > > 3 %mwa% 5 [1] 6 > 0 %mwa% 0 [1] -2
"His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich
Janus (09-19-2012)
Wasn't aware you could define your own, thanks.
"His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich
One of the most useful binary operators is %in%
Here's and example with == (wrong) and %in% (right):
And another useful one:Code:1:4 == 1:10 1:4 %in% 1:10
Code:`%truth%` <- function(x, y) {cat("Bots are scum bags\n")} 6%truth%7
"If you torture the data long enough it will eventually confess."
-Ronald Harry Coase -
bugman (09-20-2012)
Or that even assignments are functions:
Code:"<-"(x, 5) > x >[1] 5
Functions everywhere!
Code:> x <- 1:5 > "[<-"(x, 3, "a") [1] "1" "2" "a" "4" "5" > "["(x, 1) [1] 1 > print("Raptors are evil and I want them to die") # Take that trinker [1] "Raptors are evil and I want them to die")
"His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich
Functions everywhere!
Code:> x <- 1:5 > "[<-"(x, 3, "a") [1] "1" "2" "a" "4" "5" > "["(x, 1) [1] 1 > print("Raptors are evil and I want them to die") # Take that trinker [1] "Raptors are evil and I want them to die")
"His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich
trinker preempted my next question:
what is %in% doing in this line of code (from vinux's awesome ggplot2 map of Tendulakrs batting statistics)?
fasia <- world$region %in% c("India","Pakistan","Sri Lanka","Bangladesh")
The earth is round: P<0.05
bugman (09-20-2012)
It basically asks the question "Is this an element of the vector on the right" for each of the elements on the left.
Code:> 1 %in% c(1, 2, 3) # should be TRUE since 1 is in that vector [1] TRUE > 4 %in% c(1, 2, 3) # should be FALSE since 4 isn't in that vector [1] FALSE > c(1, 4) %in% c(1, 2, 3) # should be TRUE FALSE since this is vectorized [1] TRUE FALSE
"His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich
bugman (09-20-2012)
|
|