When I multiply a vector by a matrix I do:
mat <- matrix(c(c(2,3),c(4,5)),2)
vec <- c(1,-1)
vec * mat
I get
[,1] [,2]
[1,] 2 4
[2,] -3 -5
But when I try to do something similar with tibbles, like
library(dplyr)
a <- tibble(x = c(1,-1))
b <- tibble(y = c(2,3), z = c(4,5))
c <- a*b
I get the error,
Error in Ops.data.frame(a, b) :
‘*’ only defined for equally-sized data frames
In the same line of thought, how can I use transmute
to multiply variable x
by y
and x
by z
in tibble
d?
d <- tibble(x = c(1,-1), y=c(2,3), z= c(4,5))