Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
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.&nbsp; I am trying to impute the miss=
ing values and need to do it within groups.&nbsp; I am using the irmi() fun=
ction from the VIM package.&nbsp; I have found a clunky approach to get the=
 job done, but I would like to know how to do it with ddply().&nbsp; I cann=
ot figure out my problem.&nbsp; Below is an example using the sleep data fr=
ame provided in VIM.&nbsp; I created a group variable for the purpose of th=
is post.<br><br><br><br>library(VIM)<br><br>sleep$group&lt;-c(rep(1,31),rep=
(2,31))<br><br># runs fine on one group:<br>Group1_Fixed &lt;- irmi( sleep[=
sleep$group=3D=3D1, 1:7], init.method=3D"median" )<br>Group1_Fixed<br><br>#=
 this approach works:<br>Fixed &lt;- rbind.fill(<br>&nbsp; irmi(sleep[sleep=
$group=3D=3D1,1:7]) ,<br>&nbsp; irmi(sleep[sleep$group=3D=3D2,1:7]))<br>Fix=
ed<br><br># this does not work:<br>imputed &lt;- ddply(.data=3Dsleep[,1:7],=
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp; .variables=3Dsleep$group,<br>&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
; .fun=3Dirmi)<br><br><br><br><br>
------=_Part_793_30049786.1344451959619--

------=_Part_792_32080839.1344451959619--