Hello,
Try the following. The first function removes a column(s) from the
table, and the secondd all rows and columns with zero elements in them.
fun1 <- function(x, col) x[, -which(colnames(x) %in% col)]
fun2 <- function(x){
idx <- which(x == 0, arr.ind = TRUE)
x[-idx[, 1], -idx[, 2]]
}
Hope this helps,
Rui Barradas
Em 06-04-2013 07:55, Abhishek Pratap escreveu:
Hi Guys
I am back with another thing that's puzzling me.
I am creating contingency tables but then I want to filter out certain
columns and also find if any entry in the table is 0.
Example:
gts
labels A1 B2 G3
1 21 127 120
2 23 112 0
Here I want to remove B2 column from this table and also if any entry is 0
in this case G3 second row.
Missing out on how to do this in an efficient manner as I have to do this
millions of times for my data.
Thanks!
-Abhi
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.