[R] Tables package - remove NAs and NaN
Liviu Andronic
landronimirc at gmail.com
Tue Apr 23 10:19:24 CEST 2013
On Tue, Apr 23, 2013 at 10:06 AM, David Winsemius
<dwinsemius at comcast.net> wrote:
>
> On Apr 23, 2013, at 1:00 AM, David Winsemius wrote:
>
>>
>> On Apr 23, 2013, at 12:53 AM, Liviu Andronic wrote:
>>
>>> Dear David,
>>> I'm having the exact same issue as Santosh, and looking at the fix
>>> that you've provided it seems to me that results are slightly
>>> different.
>>>
>> Reverse the order of arguemtns to `interaction`:
>>
>> tabular( (`p a`=interaction(a,p, drop=TRUE, sep=" ")) ~ (N = 1) + (b + c)*
>> (mean+sd),data=q)
>
> I suppose that instead of making transpositions in the word `argument`, I should also have instead transposed the columns labels:
>
>> tabular( (`a p`=interaction(a,p, drop=TRUE, sep=" ")) ~ (N = 1) + (b + c)*
> + (mean+sd),data=q)
>
> b c
> a p N mean sd mean sd
> 1 A 10 12.8 0.7888 52.1 8.020
> 3 A 10 14.6 3.7771 56.5 6.980
> 2 B 10 16.3 3.0569 54.9 8.71
>
Thanks! The following nicely reproduces the original table:
##notice the +1
tabular( (`a p`=interaction(a,p, drop=TRUE, sep=" ") +1) ~ (N = 1) + (b + c)*
(mean+sd),data=q)
b c
a p N mean sd mean sd
1 A 10 14.20 3.490 52.2 6.779
3 A 10 16.10 2.807 59.8 7.115
2 B 10 13.90 2.807 55.1 11.060
All 30 14.73 3.107 55.7 8.836
One last bit of nitpick: Is it possible to avoid duplicate printing of
the 'A' label? With a small toy data set that is OK, but if you have
~7 categories then the resulting table can be very crowded.
Regards,
Liviu
>>
>> b c
>> p a N mean sd mean sd
>> 1 A 10 12.8 0.7888 52.1 8.020
>> 3 A 10 14.6 3.7771 56.5 6.980
>> 2 B 10 16.3 3.0569 54.9 8.711
>>
>>
>>> with(q, levels( interaction(p,a, drop=TRUE, sep=" ") ) )
>> [1] "A 1" "B 2" "A 3"
>>> with(q, levels( interaction(a,p, drop=TRUE, sep=" ") ) )
>> [1] "1 A" "3 A" "2 B"
>>
>>
>> --
>> David.
>>>
>>> On Tue, Apr 23, 2013 at 4:40 AM, David Winsemius <dwinsemius at comcast.net> wrote:
>>>>> b c
>>>>> p a N mean sd mean sd
>>>>> A 1 10 16.30 2.497 52.30 9.358
>>>>> 2 0 NaN NA NaN NA
>>>>> 3 10 15.60 2.716 60.30 8.001
>>>>> B 1 0 NaN NA NaN NA
>>>>> 2 10 15.40 2.366 57.70 10.414
>>>>> 3 0 NaN NA NaN NA
>>>>> All 30 15.77 2.473 56.77 9.601
>>>>>
>>>>> How do I remove the rows having N=0 ?
>>>>> I would like the resulting table look like..
>>>>> b c
>>>>> p a N mean sd mean sd
>>>>> A 1 10 16.30 2.497 52.30 9.358
>>>>> 3 10 15.60 2.716 60.30 8.001
>>>>> B 2 10 15.40 2.366 57.70 10.414
>>>>> All 30 15.77 2.473 56.77 9.601
>>>>
>>>> Here's a bit of a hack:
>>>>
>>>> tabular( (`p a`=interaction(p,a, drop=TRUE, sep=" ")) ~ (N = 1) + (b + c)*
>>>> (mean+sd),data=q)
>>>>
>>>> b c
>>>> p a N mean sd mean sd
>>>> A 1 10 12.8 0.7888 52.1 8.020
>>>> B 2 10 16.3 3.0569 54.9 8.711
>>>> A 3 10 14.6 3.7771 56.5 6.980
>>>>
>>> What Santosh and I would expect to get from the above is:
>>> [..]
>>> A 1 10 16.30 2.497 52.30 9.358
>>> 3 10 15.60 2.716 60.30 8.001
>>> [..]
>>>
>>> but what we get with your approach is:
>>> [..]
>>> A 1 10 12.8 0.7888 52.1 8.020
>>> B 2 10 16.3 3.0569 54.9 8.711
>>> [..]
>>>
>>> Although your approach makes things much better, can the original
>>> ordering be retained?
>>>
>>>
>>>> I have been rather hoping that Duncan Murdoch would have noticed the earlier thread, but maybe he can comment on whether there is a more direct route/
>>>>
>>> I hope so, too. Regards,
>>> Liviu
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>> ______________________________________________
>> 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
> Alameda, CA, USA
>
--
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
More information about the R-help
mailing list