I have a function that spits out a matrix, such as:
x freq
1 FALSE 40
2 TRUE 6
but when there are no FALSE values, I get
<
As @Justin said, you might be working with a data.frame
instead of a matrix
. All the better. Using your example above, if your data.frame looks as follows:
df <- data.frame(x=c(FALSE,TRUE), freq=c(40, 6))
> df
x freq
1 FALSE 40
2 TRUE 6
The following will get you what you want irrespective of whether there are FALSE
values or not.
df$freq[df$x==TRUE]
[1] 6
EDIT: As @DWin points out, you can simplify further by using the fact that df$x
is logical:
> df$freq[df$x]
[1] 6
> df$freq[!df$x]
[1] 40
For example:
> df2 <- data.frame(x=TRUE, freq=46)
> df2
x freq
1 TRUE 46
Still works:
> df2$freq[df2$x==TRUE]
[1] 46