[R] Re :argument is not numeric or logical
David Winsemius
dwinsemius at comcast.net
Sun May 2 23:25:00 CEST 2010
On May 2, 2010, at 4:25 PM, David Winsemius wrote:
>
> On May 2, 2010, at 3:27 PM, Mohan L wrote:
>
>>
>>
>> >as.numeric(assame$Login) //convert to numerics
>>
>>
>> NOOOOooooooo. You did not do what what I suggested earlier. Do not
>> reach for your keyboard in the R console until you have read the
>> FAQ section regarding converting factors to numeric. If you don't
>> want to read the FAQ
>>
>> Hi David,
>> Now I understand the trick :
>>
>> as.numeric(as.character(Login))
>>
>>
>> > avglog <-
>> with(assame,tapply(as.numeric(as.character(Login)),stdate,mean))> >
>> avglog
>> 01/11/09 00:00 02/11/09 00:00 04/11/09 00:00 05/11/09 00:00
>> 06/11/09 00:00
>> 22.04866 16.65358 15.84970 16.58600
>> 16.20743
>> 07/11/09 00:00
>> 18.52379
>>
>> But still it will not work :
>>
>> > avglog <- with(assame,tapply(as.numeric(levels(Login)
>> [as.integer(Login)]),stdate,mean))
>
> Sometimes using with(. , .) does not work when the variable name is
> buried deep in a nested set of functions. Furthermore mean needs an
> na.rm argument if, as I suspect, you now have some some NA's in the
> new variable. What happens when you:
>
> assame$Login.num <- as.numeric(as.character(assame$Login))
> avglog <-
> avglog
>
Meant to type:
avglog <- with(assame, tapply(Login.num, stdate, mean, na.rm=TRUE) )
>
> Untested of course since we STILL have no reproducible example. Had
> you used dput on head(sample, 40) or head(sample2, 40) or
> head(assame, 40) we would not still be here guessing at what you
> really are working with.
>
> --
> David.
>
>> Error in tapply(as.numeric(levels(Login)[as.integer(Login)]),
>> stdate, :
>> arguments must have same length
>>
>>
>> Thanks & Rg
>> Mohan L
>>
>>
>>
>>
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> R-help at r-project.org 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list