代码改变世界

R dataframe 遗忘, which 矩阵搜索

2017-07-25 16:31  xplorerthik  阅读(558)  评论(0编辑  收藏  举报

data frame is used for storing data tables. It is a list of vectors of equal length. For example, the following variable df is a data frame containing three vectors n, s, b.

n = c(2, 3, 5) 

s = c("aa", "bb", "cc") 

b = c(TRUE, FALSE, TRUE) 

df = data.frame(n, s, b) 
 
a <- data.frame(x = c(1,2,3), y = c(4,5,6), z = c(7,8,9))
 
x <- as.matrix(a)
idx <- which(x > 5, arr.ind=TRUE)