Hi:
Here's a data.table solution. After I read in your data as a data
frame named dd, I used str() to check its contents:
> str(dd)
'data.frame': 19 obs. of 5 variables:
$ RID : int 43 95 230 230 235 235 247 247 321 321 ...
$ SCRNO : Factor w/ 6 levels "HBA0020036","HBA0020087",..: 1 2
On Jun 30, 2011, at 12:30 PM, Marc Schwartz wrote:
> On Jun 30, 2011, at 11:20 AM, Edgar Alminar wrote:
>
I did this:
library(data.table)
dd <- data.table(bl)
dd[,sum(as.integer(CONTTIME)), by = SCRNO]
(I used as.integer because I got an error message:
On Jun 30, 2011, at 11:20 AM, Edgar Alminar wrote:
>>> I did this:
>>>
>>> library(data.table)
>>>
>>> dd <- data.table(bl)
>>> dd[,sum(as.integer(CONTTIME)), by = SCRNO]
>>>
>>> (I used as.integer because I got an error message: sum not meaningful for
>>> factors)
>>>
>>> And got this:
>>>
>> I did this:
>>
>> library(data.table)
>>
>> dd <- data.table(bl)
>> dd[,sum(as.integer(CONTTIME)), by = SCRNO]
>>
>> (I used as.integer because I got an error message: sum not meaningful for
>> factors)
>>
>> And got this:
>>
>>SCRNO V1
>> [1,] HBA0020036 111
>> [2,] HBA0020
The simplest way is:
xxx <- with(clyde,tapply(CONTTIME,SCRNO,sum))
You could also do:
xxx <- by(clyde,clyde[["SCRNO"]],function(x){sum(x[["CONTTIME"]])})
but this gives somewhat messy output; the aforesaid output may be
convenient for some purposes, not for others.
cheers,
Rolf
Hello,
I have the following dataset (this is a piece of a much larger set):
RID SCRNO VISCODE RECNO CONTTIME
2318 HBA0190012 bl 15
2418 HBA0190012 bl 35
2818 HBA0190012 bl 55
2918 HBA0190012 bl 25
321
6 matches
Mail list logo