[R] Error in which()

Sarah Goslee sarah.goslee at gmail.com
Thu Jul 8 21:47:56 CEST 2010


Congratulations, you've run afoul of:

 7.31 Why doesn't R think these numbers are equal?

> x0[7]
[1] 0.6
>
> x0[7] == .6
[1] FALSE
>

Sarah

On Thu, Jul 8, 2010 at 3:23 PM, Muhammad Rahiz
<muhammad.rahiz at ouce.ox.ac.uk> wrote:
> Hi all,
>
> I'm trying to filter data into respective numbers. For example, if the data
> ranges from 0 to <0.1, group the data. And so on for the rest of the data.
> There are inconsistencies in the output. For example, b1[[3]] lumps all the
> 0.2s and 0.3s together while 0.6s are not in the output.
>
> Running the function - table(f1) - shows that each of the components/numbers
> has x number of elements in them. But this is not showing in the results of
> the script.
>
> Can anyone assist?
>
>
> Thanks,
>
> Muhammad
>
>
>
>
> f1 <- read.table("data.txt")
> f1 <- f1[which(is.na(f1)==FALSE),1]
>
>
> x0 <- seq(0,1,0.1)
> x1 <- x0 +0.1
>
> b1 <- c()
> for (a in 1:length(x)){
> b1[[a]] <- f1[which(f1 >= x0[a] & f1 < x1[a])]
> }
>
> --



-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list