Kousei,
Your instincts are very close. Here’s a command for excluding zero-sum rows or columns.
testdataframe_subset = testdataframe[!(rowSums(testdataframe) == 0), !(colSums(testdataframe) == 0)]
The colSums
and rowSums
do what you’d expect. Note that you don’t need which
here. which
translates the vectors of TRUE/FALSE results returned by the x == 0
commands to numbers, but you can subset based on TRUE/FALSE as well as numbers. Note that !
reverses the TRUE/FALSE values.
To subset by rowname:
testdataframe_subset_ca = testdataframe_subset[grepl("^CA", rownames(testdataframe_subset)),]
grepl
searches for it’s first argument in all the values of the second argument and returns TRUE/FALSE values. Note that "^CA"
is a regular expression meaning “starts with CA”. See ?regex
for more details.
Noam
--
Check out our R resources at http://www.noamross.net/davis-r-users-group.html
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.