Message from discussion
Issue applying a function with ddply()
Received: by 10.224.180.205 with SMTP id bv13mr10547767qab.8.1344451961387;
Wed, 08 Aug 2012 11:52:41 -0700 (PDT)
X-BeenThere: manipulatr@googlegroups.com
Received: by 10.224.210.198 with SMTP id gl6ls3258777qab.4.gmail; Wed, 08 Aug
2012 11:52:40 -0700 (PDT)
Received: by 10.236.75.3 with SMTP id y3mr3959979yhd.20.1344451960731;
Wed, 08 Aug 2012 11:52:40 -0700 (PDT)
Date: Wed, 8 Aug 2012 11:52:39 -0700 (PDT)
From: David Mercer <iwidea...@gmail.com>
To: manipulatr@googlegroups.com
Message-Id: <2d4da60b-6418-4b22-a0ed-f97eec6ed0cc@googlegroups.com>
Subject: Issue applying a function with ddply()
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_792_32080839.1344451959619"
------=_Part_792_32080839.1344451959619
Content-Type: multipart/alternative;
boundary="----=_Part_793_30049786.1344451959619"
------=_Part_793_30049786.1344451959619
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
I have a data set containing 6 groups. I am trying to impute the missing
values and need to do it within groups. I am using the irmi() function
from the VIM package. I have found a clunky approach to get the job done,
but I would like to know how to do it with ddply(). I cannot figure out my
problem. Below is an example using the sleep data frame provided in VIM.
I created a group variable for the purpose of this post.
library(VIM)
sleep$group<-c(rep(1,31),rep(2,31))
# runs fine on one group:
Group1_Fixed <- irmi( sleep[sleep$group==1, 1:7], init.method="median" )
Group1_Fixed
# this approach works:
Fixed <- rbind.fill(
irmi(sleep[sleep$group==1,1:7]) ,
irmi(sleep[sleep$group==2,1:7]))
Fixed
# this does not work:
imputed <- ddply(.data=sleep[,1:7],
.variables=sleep$group,
.fun=irmi)
------=_Part_793_30049786.1344451959619
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
I have a data set containing 6 groups. I am trying to impute the miss=
ing values and need to do it within groups. I am using the irmi() fun=
ction from the VIM package. I have found a clunky approach to get the=
job done, but I would like to know how to do it with ddply(). I cann=
ot figure out my problem. Below is an example using the sleep data fr=
ame provided in VIM. I created a group variable for the purpose of th=
is post.<br><br><br><br>library(VIM)<br><br>sleep$group<-c(rep(1,31),rep=
(2,31))<br><br># runs fine on one group:<br>Group1_Fixed <- irmi( sleep[=
sleep$group=3D=3D1, 1:7], init.method=3D"median" )<br>Group1_Fixed<br><br>#=
this approach works:<br>Fixed <- rbind.fill(<br> irmi(sleep[sleep=
$group=3D=3D1,1:7]) ,<br> irmi(sleep[sleep$group=3D=3D2,1:7]))<br>Fix=
ed<br><br># this does not work:<br>imputed <- ddply(.data=3Dsleep[,1:7],=
<br>  =
; .variables=3Dsleep$group,<br> &n=
bsp;  =
; .fun=3Dirmi)<br><br><br><br><br>
------=_Part_793_30049786.1344451959619--
------=_Part_792_32080839.1344451959619--