Dataframe and vector manipulation
Post date: Apr 1, 2014 1:44:58 AM
It's fine to perform df (op) v when the vector v has the same row as df.
df1 <- data.frame("x"=c(1,0,1),"y"=c(0,0,1)) df2 <- data.frame("x"=c(2,3,1),"y"=c(0,0,1)) v <- c(1,1,1) df1 | v # > v <- c(1,1,1) # > df1 | v # x y # [1,] TRUE TRUE # [2,] TRUE TRUE # [3,] TRUE TRUE v <- c(0,0,0) df1 | v # > v <- c(0,0,0) # > df1 | v # x y # [1,] TRUE FALSE # [2,] FALSE FALSE # [3,] TRUE TRUE v <- c(0,0,0) df2 | v # > v <- c(0,0,0) # > df2 | v # x y # [1,] TRUE FALSE # [2,] TRUE FALSE # [3,] TRUE TRUE
Created by Pretty R at inside-R.org
----