[R] A whine and a request

Liaw, Andy andy_liaw at merck.com
Wed Jun 14 11:13:32 CEST 2006


I'm not sure if I understand your problem exactly, so I'm taking a wild
guess:  When you coerce a 2-d table object to data frame, what you get are
three columns: the two class variables and the frequencies.  If so, this
might help:
 
> x <- sample(1:2, 20, replace=TRUE)
> y <- sample(1:3, 20, replace=TRUE)
> tab <- table(x, y)
> as.data.frame(tab)
  x y Freq
1 1 1    2
2 2 1    2
3 1 2    7
4 2 2    2
5 1 3    3
6 2 3    4
> as.data.frame(unclass(tab))
  1 2 3
1 2 7 3
2 2 2 4

Andy

  _____  

From: r-help-bounces at stat.math.ethz.ch on behalf of John Vokey
Sent: Wed 6/14/2006 2:53 AM
To: r-help at stat.math.ethz.ch
Subject: [R] A whine and a request [Broadcast]



guRus and useRs, 

As I instruct my students: "With R what is difficult in anything  
else, is easy, usually one line of code; but, what is easy in  
anything else, is *&^%$%#$... (translation: next to impossible) in R." 

I just ran into such a case that has, to put it mildly, driven me to  
use spreadsheets (if that is not a sign of complete desperation, I  
don't know what is).  It has nothing to do with particular versions  
of R or what OS I am using, but something more fundamental.  Here it  
is.  First, I have a very large data-set (the size, though, is not  
the issue) that at base has a single binary response (score 0/1) for  
each line of the data.  Different, large blocks of the data  
correspond to the responses of single participants to stimuli  
differing in feature x, where the distribution of particular  
differences in feature x is different for each participant. Table  
(and ftable) commands are great for reducing these data to isolate  
the Freqs with which particular x values occur within each  
participant, which is what I want, including how the frequency with  
which the participant responded 1 (or 0) to that level of feature x.   
So, assiduous use of table() gives me more or less what I want:  
within participant, the values of x, the associated frequencies of 0  
responses to those values of x, and the associated frequencies of 1  
responses to those values of x.  Now, what I WANT is the simple  
regression of the proportion of 1 responses (out of the sum of 0 and  
1 responses) to each value of x on the values of x.  What table()  
gives me is close, but useless, as I can't access the columns.  But,  
applying data.frame() to the results from table, gives me access to  
the columns as variables, but returns the (re)expanded data, which  
does not allow me to compute the simple proportions I want.  After  
too many hours of trying way too many desperate commands, I gave up.   
I printed the table(), copied it to the clipboard, pasted it into a  
spreadsheet, computed the proportions, fixed the header, saved it as  
a text file, and the read it back into R to do the regressions.   
There has got to be an easier way. 
-- 
Please avoid sending me Word or PowerPoint attachments. 
See <http://www.gnu.org/philosophy/no-word-attachments.html
<http://www.gnu.org/philosophy/no-word-attachments.html> > 

-Dr. John R. Vokey 

______________________________________________ 
R-help at stat.math.ethz.ch mailing list 
https://stat.ethz.ch/mailman/listinfo/r-help
<https://stat.ethz.ch/mailman/listinfo/r-help>  
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
<http://www.R-project.org/posting-guide.html>



More information about the R-help mailing list