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
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
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
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])
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
5 matches
Mail list logo