Friends
I cannot find this documented anyplace.
I have a data frame with, say, 2 cols
d<-data.frame(x=c(1:5), y=seq(from=2, to=10, by=2))
> d
x y
1 1 2
2 2 4
3 3 6
4 4 8
5 5 10
And I want to collect each row where the first col is prime. To this end I
have a function is.prime()
I want to say something like...
q<-data.frame()
qi<-1
for(i in 1:5){
if(is.prime(d[i, 1])){
q[qi,]<-d[i,]
qi<-qi+1
}
}
but I get a "Warning in `[<-.data.frame`(`*tmp*`, qi, , value = list(x = 3L,
y = 6)) :
provided 2 variables to replace 0 variables
" message.
How can I accomplish this?
cheers
Worik
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.