Skip to content
Prev 327309 / 398502 Next

flexible approach to subsetting data

Actually the ".0" on the first variable is not needed.

You could modify the reshape() call to search for the base
name of each variable so you would not need to change the code
if the number of replications changes:

reshape(df5,  direction="long", v.names=c("dose", "resp"), 
	varying=list(dose=grepl("dose", names(df5)),
	resp=grepl("resp", names(df5)) )
      )

-------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of David
Winsemius
Sent: Tuesday, July 23, 2013 1:12 PM
To: David Winsemius
Cc: R help; Andrea Lamont
Subject: Re: [R] flexible approach to subsetting data
On Jul 23, 2013, at 10:49 AM, David Winsemius wrote:

            
Here's one of the
reshape-function
'reshape' and 'reshape2' packages were written (at least in
part) because the 'reshape'-function was so difficult to
understand.
well-respected and often extremely helpful, the function you
will want to start with is 'melt'.
since the initial direction is "long" (from "wide") and more
input would be needed.

Here's a dataset to experiment with

df5 <- data.frame(dose.0 =
c(40,50,60,50),resp.0=c(40,50,60,50), 
 dose.1 = c(1,2,1,2), resp.1=c(1,2,1,2)+3, 
 dose.2 = c(2,1,2,1), resp.2=c(1,2,1,2)+3,
 dose.3 = c(3,3,3,3), resp.3=c(1,2,1,2)+3 )

Notice that you would need add the ".0" to the column names

reshape(df5,  direction="long", 
              v.names=c("dose", "resp"), 
               varying=list(dose=c(1,3,5,7), resp=c(2,4,6,8) )
        )  # succeeds



So perhaps could use similar call (after append the ".0"'s)
with:

  varying=list(sim=seq(1,810,by=4),
               X1= seq(2,810,by=4),
               X2= seq(3,810,by=4),
               X3= seq(4,810,by=4)
               )
<alamont082 at gmail.com> wrote:
subsetting problem.
multiple imputation.
The resultant
as a separate
Here is an example
#
#
#
#
#
#
the values for the
second imputed
like this:
X3-X1).
save this to
more flexible
tedious as number
(with only 10
like to
imputations.
require naming
attempt to split properly without an explicit naming. Details
and a better description of the problem might allow more
specific answers to emerge. The fact that the first instances
have no numeric indicators may be a problem for the algorithm.
use a for loop,
having trouble
David Winsemius
Alameda, CA, USA

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible
code.