Pravin,
I did not verify that this idea will work, but I think that you could
construct a data set from Mis.X and merge that with data. Something like
this.
data <- merge(data, data.frame(Uniq.X = Mis.X), by="Uniq.X")
Dave
"Liaw, Andy"
<andy_liaw@merck.com> To: "'Pravin'"
<jadhavpr@vcu.edu>, s-news@wubios.wustl.edu
Sent by: cc:
s-news-owner@lists.biosta Subject: Re: [S]
Insert.row
t.wustl.edu
03/02/04 14:30
Pravin,
Filling in the data one column at a time isn't so terrible. What is
terrible is growing the size of the data frame one column at a time inside
the loop. Much better to add all the columns you need outside the loop,
then populate them with the data inside the loop.
HTH,
Andy
-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Pravin
Sent: Tuesday, March 02, 2004 3:07 PM
To: s-news@wubios.wustl.edu
Subject: [S] Insert.row
Hi all,
I want to insert a few rows in the data frame. It is easy using
for()--very straightforward---Following up on my previous query-- how can
I avoid for()?
Same problem!- for such a trivial stuff----------inserting 600 rows-
dos.time=25 minutes
>data$Uniq.X
[1] 1 2 3 4 5 7 9 10
> data
Uniq.X X2
1 1 12.6
2 2 12.6
3 3 8.7
4 4 10.6
5 5 11.3
6 7 11.8
7 9 8.8
8 10 14.7
>std<-1:10
>Mis.X<- setdiff(std,data$Var.X)
>Mis.X
[1] 6 8
Here is my for() logic-
>new.data<-data
>for( i in seq(along=Mis.X))
{
new.data<-insert.row(new.data,Mis.X[i],1)
new.data[Mis.X[i],1]<-Mis.X[i]
}
> new.data
Uniq.X X2
1 1 12.6
2 2 12.6
3 3 8.7
4 4 10.6
5 5 11.3
6.1 6 NA
6 7 11.8
8.1 8 NA
7 9 8.8
8 10 14.7
It works but is there any easier way to do this??? Now somehow I find
for() loops difficult. I just can't wait for 45 minutes for such a
process.
Thanks,
Pravin
Pravin Jadhav
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New
Jersey, USA 08889), and/or its affiliates (which may be known outside the
United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as
Banyu) that may be confidential, proprietary copyrighted and/or legally
privileged. It is intended solely for the use of the individual or entity
named on this message. If you are not the intended recipient, and have
received this message in error, please notify us immediately by reply
e-mail and then delete it from your system.
------------------------------------------------------------------------------
|