[R] grouping and counting in dataframe

David Winsemius dwinsemius at comcast.net
Sat Feb 26 03:48:49 CET 2011


On Feb 25, 2011, at 8:28 PM, zem wrote:

>
> hi all,
>
> i have a little problem, i have some code writen, but it is to slow...
>
> i have a dataframe with a column of time series and a grouping column,
> really there is no metter if in the first col what kind of data is,  
> it can
> be a random number like this
> x<-rnorm(10)
> gr<-c(1,3,1,2,2,4,2,3,3,3)
> x<-cbind(x,gr)

That is not a dataframe. It is a matrix. And not all time series  
objects are the same, so you should not assume that any old two column  
object will respond the same way to R functions.

>
> now i have to look for every row i , for this group, how much from  
> the x[,1]
> is in a range from x[1,i] such x[1,i] (+/-) k (k is a another number)

You may find that the function, findInterval, is useful. I cannot  
determine what you goal is from the description and there is no  
complete example with a specification of what correct output would  
be ....  as you should have seen requested in the Posting Guide.
>


-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list