Re: [R] extracting non-NA entries from a two-way frequency table

2013-12-16 Thread rmailbox
Sorry about omitting library(plyr). It's really thanks to Hadley, of course. His contributions make us all (capable of being) better. Eric - Original message - From: Michael Friendly To: rmail...@justemail.net, r-help@r-project.org Subject: Re: extracting non-NA entries from a two-way f

Re: [R] extracting non-NA entries from a two-way frequency table

2013-12-14 Thread Michael Friendly
Very elegant! Thank you Eric. (You omitted library(plyr), so I had to search for arrange()) -Michael On 12/13/2013 3:01 PM, rmail...@justemail.net wrote: Perhaps this? library(reshape2) library(stringr) GeisslerLong <- melt (Geissler, id.vars = c("boys")) GeisslerLong <- transform ( Geissler

Re: [R] extracting non-NA entries from a two-way frequency table

2013-12-13 Thread David Carlson
X 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of William Dunlap Sent: Friday, December 13, 2013 2:07 PM To: Michael Friendly; R-help Subject: Re: [R] extracting non-NA entries from a two-way frequency table The following

Re: [R] extracting non-NA entries from a two-way frequency table

2013-12-13 Thread William Dunlap
The following puts the data.frame into 'long' format and then drops rows with NA's for 'n'. f <- function(data){ df <- data.frame( expand.grid( boys = data[["boys"]], girls = as.integer(sub("^g", "", colnames(data)[-1])) ), n = unlist(data[, -1])

Re: [R] extracting non-NA entries from a two-way frequency table

2013-12-13 Thread rmailbox
Perhaps this? library(reshape2) library(stringr) GeisslerLong <- melt (Geissler, id.vars = c("boys")) GeisslerLong <- transform ( GeisslerLong, girls = as.numeric ( str_replace( variable, "g", '' )) ) GeisslerLong <- rename ( GeisslerLong, c( value = "Freq")) GeisslerLong <- arrange ( GeisslerLo