Reputation: 64024
I have a data that looks like this
Cov dis err kval n prob
1 10 0 0 0 0 7.574657e-01
2 10 0 0 0 1 2.104075e-01
3 10 0 0 0 2 2.922241e-02
4 10 0 0 1 3 2.705617e-03
5 10 0 0 1 4 1.878731e-04
6 10 0 0 0 5 1.043613e-05
7 10 0 0 0 6 4.830806e-07
8 10 0 0 0 7 1.916636e-08
9 10 1 0 0 8 6.653565e-10
10 10 1 0 0 9 2.053068e-11
11 10 1 0 0 10 5.701398e-13
What I want to do is perform a subset on that data. But why this failed?
dat.full <- read.table("http://dpaste.com/1283733/plain/",header=TRUE);
subset(dat.full,(Cov == 10 && dis==0 && err==0 && kval==1), select=prob);
It gave the following missing row output:
[1] prob
<0 rows> (or 0-length row.names)
What's the correct way to perform the subset?
I expect it to return:
4 2.705617e-03
5 1.878731e-04
Upvotes: 0
Views: 62
Reputation: 7113
You can fix this with subsetting by
subset(dat.full, (Cov == 10 & dis==0 & err==0 & kval==1), select=prob)
The problem you bumped in is, that &&
is not vectorized but should be only used for scalar values. Use &
(or |
for OR) instead.
Upvotes: 1
Reputation: 121578
You should use &
and not &&
for vectorized operations.
subset(dat.full ,Cov == 10 & dis==0 & err==0 & kval==1,select=prob)
prob
4 0.0027056170
5 0.0001878731
Upvotes: 3