storing output data from a loop that has varying row numbers

15 messages
Open this post in threaded view
|

storing output data from a loop that has varying row numbers

 Hi All, I am trying to run a loop that will have varying numbers of rows with each output. Previously I have had the same number of rows so I would use (and I appreciate that this will no doubt achieve some gasps as being thoroughly inefficient!): xdfrow<-(0) xdfrow1<-(1:32) xdfrow2<-(33:64) xdfrow3<-(65:96) xdfrow4<-(97:128) xdfrow5<-(129:160) xdfrow6<-(161:192) xdfrow7<-(193:224) and so on.... xdf <- matrix(999, nrow=1024, ncol=7) xdf <- as.data.frame(xdf) NAM <- c("NAME","ID2","DAY","BEH", "B_FALSE", "B_TRUE","TOTAL") colnames(xdf)<-NAM I then use this matrix and then run the loop and assign the data to each of the xdfrows just doing +1 on each loop. (If that makes sense? Not really important, just trying to show that I do try and solve some of my own problems, albeit perhaps not in the best manner!) _________ However, the data I'm working with now has a very varied number of rows (0:2500) over a large data set and I can't work out how is best to do this. So my loop would be: for (i in 1:33){         SEL_DAY<-seal_dist[seal_dist[,10]==i,]         print(paste("DAY", i, "of 33"))         for (s in 1:11){                         SEL_HR<-SEL_DAY[SEL_DAY[,5]==s,]         print(paste("HR", s, "of 11"))                 indx <- subset(SEL_HR, SEL_HR\$DIST == 0)                 SEL_HR\$TO_ID <- indx\$ID[match(SEL_HR\$TO, indx\$TO)]} } where i is day and s is the hr within the day, the loop works fine because it prints as i expect it too. I have not given any info on the data because I assume this is more of a method question and will be very straight forward to most people on here!? But I am happy to post data if it is needed. I assume I need to set up a matrix before the loop, e.g. DIST_LOOP<-matrix(NA,1000,ncol=11) and then I should be able to put something before the first } that allows me to add to the matrix, but everything I have tried doesn't work e.g. DIST_LOOP[[i]]<-SEL_HR Any help would be much appreciated, Best wishes, Ross
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 Hi, I might be a bit tired so that I don't understand everything but I'm a bit confused. How would you like your DIST_LOOP matrix to look like? What do you intend to use xdfrow1...xdfrow7? As I said, I might not be at the best of my shape! A sample dataset would really help to see what you have and what you want to do (maybe using dput). But maybe just: DIST_LOOP[i, ]<-SEL_HR would be enough, if you want to fill rows, as I understood. HTH, Ivan Le 6/1/2010 13:51, RCulloch a écrit : > Hi All, > > I am trying to run a loop that will have varying numbers of rows with each > output. > > Previously I have had the same number of rows so I would use (and I > appreciate that this will no doubt achieve some gasps as being thoroughly > inefficient!): > > xdfrow<-(0) > xdfrow1<-(1:32) > xdfrow2<-(33:64) > xdfrow3<-(65:96) > xdfrow4<-(97:128) > xdfrow5<-(129:160) > xdfrow6<-(161:192) > xdfrow7<-(193:224) > > and so on.... > > xdf<- matrix(999, nrow=1024, ncol=7) > xdf<- as.data.frame(xdf) > NAM<- c("NAME","ID2","DAY","BEH", "B_FALSE", "B_TRUE","TOTAL") > colnames(xdf)<-NAM > > I then use this matrix and then run the loop and assign the data to each of > the xdfrows just doing +1 on each loop. (If that makes sense? Not really > important, just trying to show that I do try and solve some of my own > problems, albeit perhaps not in the best manner!) > > _________ > > However, the data I'm working with now has a very varied number of rows > (0:2500) over a large data set and I can't work out how is best to do this. > > So my loop would be: > > for (i in 1:33){ > SEL_DAY<-seal_dist[seal_dist[,10]==i,] > print(paste("DAY", i, "of 33")) > for (s in 1:11){ > SEL_HR<-SEL_DAY[SEL_DAY[,5]==s,] > print(paste("HR", s, "of 11")) > indx<- subset(SEL_HR, SEL_HR\$DIST == 0) > SEL_HR\$TO_ID<- indx\$ID[match(SEL_HR\$TO, indx\$TO)]} > } > > where i is day and s is the hr within the day, the loop works fine because > it prints as i expect it too. I have not given any info on the data because > I assume this is more of a method question and will be very straight forward > to most people on here!? But I am happy to post data if it is needed. > > I assume I need to set up a matrix before the loop, > > e.g. DIST_LOOP<-matrix(NA,1000,ncol=11) > > and then I should be able to put something before the first } that allows me > to add to the matrix, but everything I have tried doesn't work > > e.g. DIST_LOOP[[i]]<-SEL_HR > > Any help would be much appreciated, > > Best wishes, > > Ross > > > > > >     -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 [hidden email] ********** http://www.for771.uni-bonn.dehttp://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 Hi Ivan, Thanks for your help, your initial suggestion did not work, but that is no doubt down to my lack of making sense! Here is a short example of my dataset. Basically the loop is set up to match the ID with the TO column based on DIST = 0. So A1 = 2, A1.1 =1, A2 = 4, A2.1 = 3. That is fine for HR 9, but for HR 10 the numbers no longer match those IDs so I need to loop the data and store each loop - if that makes sense.   FROM TO     DIST      ID HR DD MM YY ANIMAL DAY 1     1  1  2.63981    'A1'  9 30  9  7      1   1 2     1  2  0.00000    'A1'  9 30  9  7      1   1 3     1  3  6.95836    'A1'  9 30  9  7      1   1 4     1  4  8.63809    'A1'  9 30  9  7      1   1 5     1  1  0.00000  'A1.1'  9 30  9  7      7   1 6     1  2  2.63981  'A1.1'  9 30  9  7      7   1 7     1  3  8.03071  'A1.1'  9 30  9  7      7   1 8     1  4  8.90896  'A1.1'  9 30  9  7      7   1 9     1  1  8.90896    'A2'  9 30  9  7      1   1 10    1  2  8.63809    'A2'  9 30  9  7      1   1 11    1  3  2.85602    'A2'  9 30  9  7      1   1 12    1  4  0.00000    'A2'  9 30  9  7      1   1 13    1  1  8.03071  'A2.1'  9 30  9  7      7   1 14    1  2  6.95836  'A2.1'  9 30  9  7      7   1 15    1  3  0.00000  'A2.1'  9 30  9  7      7   1 16    1  4  2.85602   A2.1'  9 30  9  7      7   1 17    1  1  3.53695    'A1' 10 30  9  7      1   1 18    1  2  4.32457    'A1' 10 30  9  7      1   1 19    1  3  0.00000    'A1' 10 30  9  7      1   1 20    1  4  8.85851    'A1' 10 30  9  7      1   1 21    1  5 12.09194    'A1' 10 30  9  7      1   1 22    1  1  7.44743  'A1.1' 10 30  9  7      7   1 23    1  2  0.00000  'A1.1' 10 30  9  7      7   1 24    1  3  4.32457  'A1.1' 10 30  9  7      7   1 25    1  4 13.16728  'A1.1' 10 30  9  7      7   1 26    1  5 16.34761  'A1.1' 10 30  9  7      7   1 27    1  1  6.13176    'A2' 10 30  9  7      1   1 28    1  2 13.16728    'A2' 10 30  9  7      1   1 29    1  3  8.85851    'A2' 10 30  9  7      1   1 30    1  4  0.00000    'A2' 10 30  9  7      1   1 31    1  5  3.40726    'A2' 10 30  9  7      1   1 32    1  1  9.03345  'A2.1' 10 30  9  7      7   1 33    1  2 16.34761  'A2.1' 10 30  9  7      7   1 34    1  3 12.09194  'A2.1' 10 30  9  7      7   1 35    1  4  3.40726  'A2.1' 10 30  9  7      7   1 36    1  5  0.00000  'A2.1' 10 30  9  7      7   1 37    1  1  0.00000 'MALE1' 10 30  9  7     12   1 38    1  2  7.44743 'MALE1' 10 30  9  7     12   1 39    1  3  3.53695 'MALE1' 10 30  9  7     12   1 40    1  4  6.13176 'MALE1' 10 30  9  7     12   1 41    1  5  9.03345 'MALE1' 10 30  9  7     12   1 So the loop is: DIST_LOOP<-matrix(NA,NA,ncol=11) for (i in 1:33){         SEL_DAY<-seal_dist[seal_dist[,10]==i,]         SEL_DAY[i]=dist[i]         print(paste("DAY", i, "of 33"))         for (s in 1:11){                         SEL_HR<-SEL_DAY[SEL_DAY[,5]==s,]         print(paste("HR", s, "of 11"))                 indx <- subset(SEL_HR, SEL_HR\$DIST == 0)                 SEL_HR\$TO_ID <- indx\$ID[match(SEL_HR\$TO, indx\$TO)]         DIST_LOOP[i,]<-SEL_HR         }         } But storing the data in the DIST_LOOP matrix doesn't work, I am just told in another post that a list might be better than a matrix? I hope this makes more sense!? Many thanks, Ross
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 In reply to this post by RCulloch There's something very unlogic in your code. You have the whole time the same datafra On Tue, Jun 1, 2010 at 1:51 PM, RCulloch <[hidden email]> wrote: > > Hi All, > > I am trying to run a loop that will have varying numbers of rows with each > output. > > Previously I have had the same number of rows so I would use (and I > appreciate that this will no doubt achieve some gasps as being thoroughly > inefficient!): > > xdfrow<-(0) > xdfrow1<-(1:32) > xdfrow2<-(33:64) > xdfrow3<-(65:96) > xdfrow4<-(97:128) > xdfrow5<-(129:160) > xdfrow6<-(161:192) > xdfrow7<-(193:224) > > and so on.... > > xdf <- matrix(999, nrow=1024, ncol=7) > xdf <- as.data.frame(xdf) > NAM <- c("NAME","ID2","DAY","BEH", "B_FALSE", "B_TRUE","TOTAL") > colnames(xdf)<-NAM > > I then use this matrix and then run the loop and assign the data to each of > the xdfrows just doing +1 on each loop. (If that makes sense? Not really > important, just trying to show that I do try and solve some of my own > problems, albeit perhaps not in the best manner!) > > _________ > > However, the data I'm working with now has a very varied number of rows > (0:2500) over a large data set and I can't work out how is best to do this. > > So my loop would be: > > for (i in 1:33){ >        SEL_DAY<-seal_dist[seal_dist[,10]==i,] >        print(paste("DAY", i, "of 33")) >        for (s in 1:11){ >                        SEL_HR<-SEL_DAY[SEL_DAY[,5]==s,] >        print(paste("HR", s, "of 11")) >                indx <- subset(SEL_HR, SEL_HR\$DIST == 0) >                SEL_HR\$TO_ID <- indx\$ID[match(SEL_HR\$TO, indx\$TO)]} > } > > where i is day and s is the hr within the day, the loop works fine because > it prints as i expect it too. I have not given any info on the data because > I assume this is more of a method question and will be very straight > forward > to most people on here!? But I am happy to post data if it is needed. > > I assume I need to set up a matrix before the loop, > > e.g. DIST_LOOP<-matrix(NA,1000,ncol=11) > > and then I should be able to put something before the first } that allows > me > to add to the matrix, but everything I have tried doesn't work > > e.g. DIST_LOOP[[i]]<-SEL_HR > > Any help would be much appreciated, > > Best wishes, > > Ross > > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/storing-output-data-from-a-loop-that-has-varying-row-numbers-tp2238396p2238396.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] 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. > -- Joris Meys Statistical Consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control Coupure Links 653 B-9000 Gent tel : +32 9 264 59 87 [hidden email] ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php        [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 In reply to this post by RCulloch could you just give us the output of dput() for the data you copied in the mail? eg dput(seal_dist[,1:100]) and an example of how you want your output. I guess I get what you want to do, but it's not what your code is doing. And it will be difficult to put that in a matrix, as you have different labels and different numbers of TO-levels for different days and HR values. Cheers On Tue, Jun 1, 2010 at 3:32 PM, RCulloch <[hidden email]> wrote: > > Hi Ivan, > > Thanks for your help, your initial suggestion did not work, but that is no > doubt down to my lack of making sense! > > Here is a short example of my dataset. Basically the loop is set up to > match > the ID with the TO column based on DIST = 0. So A1 = 2, A1.1 =1, A2 = 4, > A2.1 = 3. That is fine for HR 9, but for HR 10 the numbers no longer match > those IDs so I need to loop the data and store each loop - if that makes > sense. > > >  FROM TO     DIST      ID HR DD MM YY ANIMAL DAY > 1     1  1  2.63981    'A1'  9 30  9  7      1   1 > 2     1  2  0.00000    'A1'  9 30  9  7      1   1 > 3     1  3  6.95836    'A1'  9 30  9  7      1   1 > 4     1  4  8.63809    'A1'  9 30  9  7      1   1 > 5     1  1  0.00000  'A1.1'  9 30  9  7      7   1 > 6     1  2  2.63981  'A1.1'  9 30  9  7      7   1 > 7     1  3  8.03071  'A1.1'  9 30  9  7      7   1 > 8     1  4  8.90896  'A1.1'  9 30  9  7      7   1 > 9     1  1  8.90896    'A2'  9 30  9  7      1   1 > 10    1  2  8.63809    'A2'  9 30  9  7      1   1 > 11    1  3  2.85602    'A2'  9 30  9  7      1   1 > 12    1  4  0.00000    'A2'  9 30  9  7      1   1 > 13    1  1  8.03071  'A2.1'  9 30  9  7      7   1 > 14    1  2  6.95836  'A2.1'  9 30  9  7      7   1 > 15    1  3  0.00000  'A2.1'  9 30  9  7      7   1 > 16    1  4  2.85602   A2.1'  9 30  9  7      7   1 > 17    1  1  3.53695    'A1' 10 30  9  7      1   1 > 18    1  2  4.32457    'A1' 10 30  9  7      1   1 > 19    1  3  0.00000    'A1' 10 30  9  7      1   1 > 20    1  4  8.85851    'A1' 10 30  9  7      1   1 > 21    1  5 12.09194    'A1' 10 30  9  7      1   1 > 22    1  1  7.44743  'A1.1' 10 30  9  7      7   1 > 23    1  2  0.00000  'A1.1' 10 30  9  7      7   1 > 24    1  3  4.32457  'A1.1' 10 30  9  7      7   1 > 25    1  4 13.16728  'A1.1' 10 30  9  7      7   1 > 26    1  5 16.34761  'A1.1' 10 30  9  7      7   1 > 27    1  1  6.13176    'A2' 10 30  9  7      1   1 > 28    1  2 13.16728    'A2' 10 30  9  7      1   1 > 29    1  3  8.85851    'A2' 10 30  9  7      1   1 > 30    1  4  0.00000    'A2' 10 30  9  7      1   1 > 31    1  5  3.40726    'A2' 10 30  9  7      1   1 > 32    1  1  9.03345  'A2.1' 10 30  9  7      7   1 > 33    1  2 16.34761  'A2.1' 10 30  9  7      7   1 > 34    1  3 12.09194  'A2.1' 10 30  9  7      7   1 > 35    1  4  3.40726  'A2.1' 10 30  9  7      7   1 > 36    1  5  0.00000  'A2.1' 10 30  9  7      7   1 > 37    1  1  0.00000 'MALE1' 10 30  9  7     12   1 > 38    1  2  7.44743 'MALE1' 10 30  9  7     12   1 > 39    1  3  3.53695 'MALE1' 10 30  9  7     12   1 > 40    1  4  6.13176 'MALE1' 10 30  9  7     12   1 > 41    1  5  9.03345 'MALE1' 10 30  9  7     12   1 > > > So the loop is: > > DIST_LOOP<-matrix(NA,NA,ncol=11) > > for (i in 1:33){ >        SEL_DAY<-seal_dist[seal_dist[,10]==i,] >         SEL_DAY[i]=dist[i] >         print(paste("DAY", i, "of 33")) >        for (s in 1:11){ >                        SEL_HR<-SEL_DAY[SEL_DAY[,5]==s,] >        print(paste("HR", s, "of 11")) >                indx <- subset(SEL_HR, SEL_HR\$DIST == 0) >                SEL_HR\$TO_ID <- indx\$ID[match(SEL_HR\$TO, indx\$TO)] >         DIST_LOOP[i,]<-SEL_HR >        } >        } > > But storing the data in the DIST_LOOP matrix doesn't work, I am just told > in > another post that a list might be better than a matrix? > > I hope this makes more sense!? > > Many thanks, > > Ross > -- > View this message in context: > http://r.789695.n4.nabble.com/storing-output-data-from-a-loop-that-has-varying-row-numbers-tp2238396p2238483.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] 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. > -- Joris Meys Statistical Consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control Coupure Links 653 B-9000 Gent tel : +32 9 264 59 87 [hidden email] ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php        [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 Hi Joris, Thanks for your help! The data as requested: structure(list(FROM = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),     TO = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L,     2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L,     3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), DIST = c(2.63981,     0, 6.95836, 8.63809, 0, 2.63981, 8.03071, 8.90896, 8.90896,     8.63809, 2.85602, 0, 8.03071, 6.95836, 0, 2.85602, 3.53695,     4.32457, 0, 8.85851, 12.09194, 7.44743, 0, 4.32457, 13.16728,     16.34761, 6.13176, 13.16728, 8.85851, 0, 3.40726, 9.03345,     16.34761, 12.09194, 3.40726, 0, 0, 7.44743, 3.53695, 6.13176,     9.03345), ID = structure(c(12L, 12L, 12L, 12L, 11L, 11L,     11L, 11L, 14L, 14L, 14L, 14L, 13L, 13L, 13L, 143L, 12L, 12L,     12L, 12L, 12L, 11L, 11L, 11L, 11L, 11L, 14L, 14L, 14L, 14L,     14L, 13L, 13L, 13L, 13L, 13L, 94L, 94L, 94L, 94L, 94L), .Label = c("'11.1'",     "'15.1'", "'15.5'", "'18.1'", "'24.2'", "'26.1'", "'26.2'",     "'28.3'", "'4.2'", "'7.1'", "'A1.1'", "'A1'", "'A2.1'", "'A2'",     "'B1'", "'C1'", "'D1.1'", "'D1'", "'D2.1'", "'D2'", "'D3.1'",     "'D3'", "'D4.1'", "'D4'", "'D5.1'", "'D5'", "'D6.1'", "'D6'",     "'E1.1'", "'E1'", "'E2.1'", "'E2'", "'E4'", "'E5'", "'F1.1'",     "'F1'", "'F10.1'", "'F10'", "'F11'", "'F2'", "'F3'", "'F4.1'",     "'F4'", "'F5.1'", "'F5'", "'F7'", "'F8.1'", "'F8'", "'G2.1'",     "'G2'", "'G3.1'", "'G3'", "'G4.1'", "'G4'", "'G5.1'", "'G5'",     "'H1.1'", "'H1'", "'H2'", "'H3.1'", "'H3'", "'H8'", "'I1.1'",     "'I1'", "'I2'", "'I4.1'", "'I4'", "'J1.1'", "'J1'", "'J2.1'",     "'J2'", "'J3'", "'J6'", "'J7'", "'JUV'", "'K1.1'", "'K1'",     "'K2'", "'K3'", "'K4.1'", "'K4'", "'L1.1'", "'L1'", "'L2.1'",     "'L2'", "'L4'", "'M1'", "'M2.1'", "'M2'", "'M3.1'", "'M3'",     "'M4.1'", "'M4'", "'MALE1'", "'N1.1'", "'N1'", "'N2'", "'N3'",     "'N4.1'", "'N4'", "'O1'", "'O2'", "'O3.1'", "'O3'", "'O4.1'",     "'O4'", "'O5'", "'P1.1'", "'P1'", "'Q1'", "'Q2'", "'Q3'",     "'R1.1'", "'R1'", "'R2'", "'R3.1'", "'R3'", "'R4.1'", "'R4'",     "'R5.1'", "'R5'", "'S1.1'", "'S1'", "'S2.1'", "'S2'", "'S3.1'",     "'S3'", "'S4.1'", "'S4'", "'T1'", "'U1.1'", "'U1'", "'U2'",     "'U3'", "'UKFEM'", "'UKMAL'", "'UKPUP'", "'V1.1'", "'V1'",     "'W1.1'", "'W1'", "'WR'", "A2.1'"), class = "factor"), HR = c(9L,     9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,     10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,     10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,     10L), DD = c(30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,     30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,     30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,     30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L), MM = c(9L, 9L, 9L,     9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,     9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,     9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), YY = c(7L, 7L, 7L, 7L, 7L,     7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,     7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,     7L, 7L, 7L, 7L, 7L, 7L), ANIMAL = c(1L, 1L, 1L, 1L, 7L, 7L,     7L, 7L, 1L, 1L, 1L, 1L, 7L, 7L, 7L, 7L, 1L, 1L, 1L, 1L, 1L,     7L, 7L, 7L, 7L, 7L, 1L, 1L, 1L, 1L, 1L, 7L, 7L, 7L, 7L, 7L,     12L, 12L, 12L, 12L, 12L), DAY = c(1L, 1L, 1L, 1L, 1L, 1L,     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,     1L, 1L, 1L, 1L, 1L)), .Names = c("FROM", "TO", "DIST", "ID", "HR", "DD", "MM", "YY", "ANIMAL", "DAY"), row.names = c(NA, 41L ), class = "data.frame") The output should be as the original file is, but it should have an additional column for 'TO_ID' I hope that makes sense? Cheers, Ross
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 In reply to this post by RCulloch Hi Ross, I'm still really confused about your question. Let me ask you some specific questions (maybe someone more experienced would understand at once, but I'm no expert; I hope I can still help you! In any case, I would like to understand for myself ;) ) - is "seal_dist" the name of your data.frame? - what do you want to do with SEL_DAY[i]=dist[i] ? What is "dist"? If I understand well, you want to replace the values in FROM (then TO, then DIST...) with the values from the same column number in dist? - Since I still haven't understood your goal completely, I still don't understand why you add the column TO_ID to SEL_HR. - In any case, a matrix cannot work because you want to store data of different classes in DIST_LOOP (ID is character and the others are numeric). You can either use a data.frame (if you really want to have the table-like structure, which is a list) or a list. - Moreover, the output from dput(your data) would really help to see what you have! HTH, Ivan Le 6/1/2010 15:32, RCulloch a écrit : > Hi Ivan, > > Thanks for your help, your initial suggestion did not work, but that is no > doubt down to my lack of making sense! > > Here is a short example of my dataset. Basically the loop is set up to match > the ID with the TO column based on DIST = 0. So A1 = 2, A1.1 =1, A2 = 4, > A2.1 = 3. That is fine for HR 9, but for HR 10 the numbers no longer match > those IDs so I need to loop the data and store each loop - if that makes > sense. > > >    FROM TO     DIST      ID HR DD MM YY ANIMAL DAY > 1     1  1  2.63981    'A1'  9 30  9  7      1   1 > 2     1  2  0.00000    'A1'  9 30  9  7      1   1 > 3     1  3  6.95836    'A1'  9 30  9  7      1   1 > 4     1  4  8.63809    'A1'  9 30  9  7      1   1 > 5     1  1  0.00000  'A1.1'  9 30  9  7      7   1 > 6     1  2  2.63981  'A1.1'  9 30  9  7      7   1 > 7     1  3  8.03071  'A1.1'  9 30  9  7      7   1 > 8     1  4  8.90896  'A1.1'  9 30  9  7      7   1 > 9     1  1  8.90896    'A2'  9 30  9  7      1   1 > 10    1  2  8.63809    'A2'  9 30  9  7      1   1 > 11    1  3  2.85602    'A2'  9 30  9  7      1   1 > 12    1  4  0.00000    'A2'  9 30  9  7      1   1 > 13    1  1  8.03071  'A2.1'  9 30  9  7      7   1 > 14    1  2  6.95836  'A2.1'  9 30  9  7      7   1 > 15    1  3  0.00000  'A2.1'  9 30  9  7      7   1 > 16    1  4  2.85602   A2.1'  9 30  9  7      7   1 > 17    1  1  3.53695    'A1' 10 30  9  7      1   1 > 18    1  2  4.32457    'A1' 10 30  9  7      1   1 > 19    1  3  0.00000    'A1' 10 30  9  7      1   1 > 20    1  4  8.85851    'A1' 10 30  9  7      1   1 > 21    1  5 12.09194    'A1' 10 30  9  7      1   1 > 22    1  1  7.44743  'A1.1' 10 30  9  7      7   1 > 23    1  2  0.00000  'A1.1' 10 30  9  7      7   1 > 24    1  3  4.32457  'A1.1' 10 30  9  7      7   1 > 25    1  4 13.16728  'A1.1' 10 30  9  7      7   1 > 26    1  5 16.34761  'A1.1' 10 30  9  7      7   1 > 27    1  1  6.13176    'A2' 10 30  9  7      1   1 > 28    1  2 13.16728    'A2' 10 30  9  7      1   1 > 29    1  3  8.85851    'A2' 10 30  9  7      1   1 > 30    1  4  0.00000    'A2' 10 30  9  7      1   1 > 31    1  5  3.40726    'A2' 10 30  9  7      1   1 > 32    1  1  9.03345  'A2.1' 10 30  9  7      7   1 > 33    1  2 16.34761  'A2.1' 10 30  9  7      7   1 > 34    1  3 12.09194  'A2.1' 10 30  9  7      7   1 > 35    1  4  3.40726  'A2.1' 10 30  9  7      7   1 > 36    1  5  0.00000  'A2.1' 10 30  9  7      7   1 > 37    1  1  0.00000 'MALE1' 10 30  9  7     12   1 > 38    1  2  7.44743 'MALE1' 10 30  9  7     12   1 > 39    1  3  3.53695 'MALE1' 10 30  9  7     12   1 > 40    1  4  6.13176 'MALE1' 10 30  9  7     12   1 > 41    1  5  9.03345 'MALE1' 10 30  9  7     12   1 > > > So the loop is: > > DIST_LOOP<-matrix(NA,NA,ncol=11) > > for (i in 1:33){ > SEL_DAY<-seal_dist[seal_dist[,10]==i,] > SEL_DAY[i]=dist[i] > print(paste("DAY", i, "of 33")) > for (s in 1:11){ > SEL_HR<-SEL_DAY[SEL_DAY[,5]==s,] > print(paste("HR", s, "of 11")) > indx<- subset(SEL_HR, SEL_HR\$DIST == 0) > SEL_HR\$TO_ID<- indx\$ID[match(SEL_HR\$TO, indx\$TO)] > DIST_LOOP[i,]<-SEL_HR > } > } > > But storing the data in the DIST_LOOP matrix doesn't work, I am just told in > another post that a list might be better than a matrix? > > I hope this makes more sense!? > > Many thanks, > > Ross >     -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 [hidden email] ********** http://www.for771.uni-bonn.dehttp://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 Hi Ivan, Thanks again for your help! I'll just go through your questions... I'm still really confused about your question. -Sorry!!! Let me ask you some specific questions (maybe someone more experienced would understand at once, but I'm no expert; I hope I can still help you! In any case, I would like to understand for myself ;) ) - is "seal_dist" the name of your data.frame? yes so.. head(seal_dist)   FROM TO    DIST     ID HR DD MM YY ANIMAL DAY 1    1  1 2.63981   'A1'  9 30  9  7      1   1 2    1  2 0.00000   'A1'  9 30  9  7      1   1 3    1  3 6.95836   'A1'  9 30  9  7      1   1 4    1  4 8.63809   'A1'  9 30  9  7      1   1 5    1  1 0.00000 'A1.1'  9 30  9  7      7   1 6    1  2 2.63981 'A1.1'  9 30  9  7      7   1 - what do you want to do with SEL_DAY[i]=dist[i] That was a (desperate) attempt to do 'something', but didn't work - so shouldn't have been in the script I posted, sorry! ? What is "dist"? It is a measure of distance from one point (ID) to another i.e. the distance between A1 and A1.1 If I understand well, you want to replace the values in FROM (then TO, then DIST...) with the values from the same column number in dist? The problem is that Arc doesn't output the data as I'd like, so I want to create a new column to add to the data. What Arc has done is taken a distance between each ID for each hour, but because the number of IDs in each hour don't match it means that the TO number is not unique to the ID throughout the entire dataset, only on that given hour. So when distance = 0 in the TO column then that TO number -s equal to the ID i.e. the distance to A1 to A1 is 0, so I then want to use that information to create a new column that will tell me the actual ID. If that is any clearer? - Since I still haven't understood your goal completely, I still don't understand why you add the column TO_ID to SEL_HR. see above - In any case, a matrix cannot work because you want to store data of different classes in DIST_LOOP (ID is character and the others are numeric). You can either use a data.frame (if you really want to have the table-like structure, which is a list) or a list. I see, can you advise on how to set up a list to write to? - Moreover, the output from dput(your data) would really help to see what you have! I have not long posted it, I hope it helps!! Thanks again for your help Ivan, much appreciated, Ross
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 In reply to this post by RCulloch Is this what you're looking for? seal_list <- split(seal_dist,sel) out <- lapply(seal_list,function(x){       indx <- subset(x, x\$DIST == 0)       x\$TO_ID <- indx\$ID[match(x\$TO, indx\$TO)]       return(x) }) output <- unsplit(out,sel) Cheers Joris On Tue, Jun 1, 2010 at 3:32 PM, RCulloch <[hidden email]> wrote: > > Hi Ivan, > > Thanks for your help, your initial suggestion did not work, but that is no > doubt down to my lack of making sense! > > Here is a short example of my dataset. Basically the loop is set up to > match > the ID with the TO column based on DIST = 0. So A1 = 2, A1.1 =1, A2 = 4, > A2.1 = 3. That is fine for HR 9, but for HR 10 the numbers no longer match > those IDs so I need to loop the data and store each loop - if that makes > sense. > > >  FROM TO     DIST      ID HR DD MM YY ANIMAL DAY > 1     1  1  2.63981    'A1'  9 30  9  7      1   1 > 2     1  2  0.00000    'A1'  9 30  9  7      1   1 > 3     1  3  6.95836    'A1'  9 30  9  7      1   1 > 4     1  4  8.63809    'A1'  9 30  9  7      1   1 > 5     1  1  0.00000  'A1.1'  9 30  9  7      7   1 > 6     1  2  2.63981  'A1.1'  9 30  9  7      7   1 > 7     1  3  8.03071  'A1.1'  9 30  9  7      7   1 > 8     1  4  8.90896  'A1.1'  9 30  9  7      7   1 > 9     1  1  8.90896    'A2'  9 30  9  7      1   1 > 10    1  2  8.63809    'A2'  9 30  9  7      1   1 > 11    1  3  2.85602    'A2'  9 30  9  7      1   1 > 12    1  4  0.00000    'A2'  9 30  9  7      1   1 > 13    1  1  8.03071  'A2.1'  9 30  9  7      7   1 > 14    1  2  6.95836  'A2.1'  9 30  9  7      7   1 > 15    1  3  0.00000  'A2.1'  9 30  9  7      7   1 > 16    1  4  2.85602   A2.1'  9 30  9  7      7   1 > 17    1  1  3.53695    'A1' 10 30  9  7      1   1 > 18    1  2  4.32457    'A1' 10 30  9  7      1   1 > 19    1  3  0.00000    'A1' 10 30  9  7      1   1 > 20    1  4  8.85851    'A1' 10 30  9  7      1   1 > 21    1  5 12.09194    'A1' 10 30  9  7      1   1 > 22    1  1  7.44743  'A1.1' 10 30  9  7      7   1 > 23    1  2  0.00000  'A1.1' 10 30  9  7      7   1 > 24    1  3  4.32457  'A1.1' 10 30  9  7      7   1 > 25    1  4 13.16728  'A1.1' 10 30  9  7      7   1 > 26    1  5 16.34761  'A1.1' 10 30  9  7      7   1 > 27    1  1  6.13176    'A2' 10 30  9  7      1   1 > 28    1  2 13.16728    'A2' 10 30  9  7      1   1 > 29    1  3  8.85851    'A2' 10 30  9  7      1   1 > 30    1  4  0.00000    'A2' 10 30  9  7      1   1 > 31    1  5  3.40726    'A2' 10 30  9  7      1   1 > 32    1  1  9.03345  'A2.1' 10 30  9  7      7   1 > 33    1  2 16.34761  'A2.1' 10 30  9  7      7   1 > 34    1  3 12.09194  'A2.1' 10 30  9  7      7   1 > 35    1  4  3.40726  'A2.1' 10 30  9  7      7   1 > 36    1  5  0.00000  'A2.1' 10 30  9  7      7   1 > 37    1  1  0.00000 'MALE1' 10 30  9  7     12   1 > 38    1  2  7.44743 'MALE1' 10 30  9  7     12   1 > 39    1  3  3.53695 'MALE1' 10 30  9  7     12   1 > 40    1  4  6.13176 'MALE1' 10 30  9  7     12   1 > 41    1  5  9.03345 'MALE1' 10 30  9  7     12   1 > > > So the loop is: > > DIST_LOOP<-matrix(NA,NA,ncol=11) > > for (i in 1:33){ >        SEL_DAY<-seal_dist[seal_dist[,10]==i,] >         SEL_DAY[i]=dist[i] >         print(paste("DAY", i, "of 33")) >        for (s in 1:11){ >                        SEL_HR<-SEL_DAY[SEL_DAY[,5]==s,] >        print(paste("HR", s, "of 11")) >                indx <- subset(SEL_HR, SEL_HR\$DIST == 0) >                SEL_HR\$TO_ID <- indx\$ID[match(SEL_HR\$TO, indx\$TO)] >         DIST_LOOP[i,]<-SEL_HR >        } >        } > > But storing the data in the DIST_LOOP matrix doesn't work, I am just told > in > another post that a list might be better than a matrix? > > I hope this makes more sense!? > > Many thanks, > > Ross > -- > View this message in context: > http://r.789695.n4.nabble.com/storing-output-data-from-a-loop-that-has-varying-row-numbers-tp2238396p2238483.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] 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. > -- Joris Meys Statistical Consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control Coupure Links 653 B-9000 Gent tel : +32 9 264 59 87 [hidden email] ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php        [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 Sorry, forgot to add the sel. This is the first line, then just run the rest. sel <- as.factor(paste(seal_dist[,10],"-",seal_dist[,5],sep="")) cheers Joris On Tue, Jun 1, 2010 at 4:56 PM, Joris Meys <[hidden email]> wrote: > Is this what you're looking for? > > seal_list <- split(seal_dist,sel) > > out <- lapply(seal_list,function(x){ >       indx <- subset(x, x\$DIST == 0) >       x\$TO_ID <- indx\$ID[match(x\$TO, indx\$TO)] >       return(x) > }) > > output <- unsplit(out,sel) > > Cheers > Joris > > On Tue, Jun 1, 2010 at 3:32 PM, RCulloch <[hidden email]> wrote: > >> >> Hi Ivan, >> >> Thanks for your help, your initial suggestion did not work, but that is no >> doubt down to my lack of making sense! >> >> Here is a short example of my dataset. Basically the loop is set up to >> match >> the ID with the TO column based on DIST = 0. So A1 = 2, A1.1 =1, A2 = 4, >> A2.1 = 3. That is fine for HR 9, but for HR 10 the numbers no longer match >> those IDs so I need to loop the data and store each loop - if that makes >> sense. >> >> >>  FROM TO     DIST      ID HR DD MM YY ANIMAL DAY >> 1     1  1  2.63981    'A1'  9 30  9  7      1   1 >> 2     1  2  0.00000    'A1'  9 30  9  7      1   1 >> 3     1  3  6.95836    'A1'  9 30  9  7      1   1 >> 4     1  4  8.63809    'A1'  9 30  9  7      1   1 >> 5     1  1  0.00000  'A1.1'  9 30  9  7      7   1 >> 6     1  2  2.63981  'A1.1'  9 30  9  7      7   1 >> 7     1  3  8.03071  'A1.1'  9 30  9  7      7   1 >> 8     1  4  8.90896  'A1.1'  9 30  9  7      7   1 >> 9     1  1  8.90896    'A2'  9 30  9  7      1   1 >> 10    1  2  8.63809    'A2'  9 30  9  7      1   1 >> 11    1  3  2.85602    'A2'  9 30  9  7      1   1 >> 12    1  4  0.00000    'A2'  9 30  9  7      1   1 >> 13    1  1  8.03071  'A2.1'  9 30  9  7      7   1 >> 14    1  2  6.95836  'A2.1'  9 30  9  7      7   1 >> 15    1  3  0.00000  'A2.1'  9 30  9  7      7   1 >> 16    1  4  2.85602   A2.1'  9 30  9  7      7   1 >> 17    1  1  3.53695    'A1' 10 30  9  7      1   1 >> 18    1  2  4.32457    'A1' 10 30  9  7      1   1 >> 19    1  3  0.00000    'A1' 10 30  9  7      1   1 >> 20    1  4  8.85851    'A1' 10 30  9  7      1   1 >> 21    1  5 12.09194    'A1' 10 30  9  7      1   1 >> 22    1  1  7.44743  'A1.1' 10 30  9  7      7   1 >> 23    1  2  0.00000  'A1.1' 10 30  9  7      7   1 >> 24    1  3  4.32457  'A1.1' 10 30  9  7      7   1 >> 25    1  4 13.16728  'A1.1' 10 30  9  7      7   1 >> 26    1  5 16.34761  'A1.1' 10 30  9  7      7   1 >> 27    1  1  6.13176    'A2' 10 30  9  7      1   1 >> 28    1  2 13.16728    'A2' 10 30  9  7      1   1 >> 29    1  3  8.85851    'A2' 10 30  9  7      1   1 >> 30    1  4  0.00000    'A2' 10 30  9  7      1   1 >> 31    1  5  3.40726    'A2' 10 30  9  7      1   1 >> 32    1  1  9.03345  'A2.1' 10 30  9  7      7   1 >> 33    1  2 16.34761  'A2.1' 10 30  9  7      7   1 >> 34    1  3 12.09194  'A2.1' 10 30  9  7      7   1 >> 35    1  4  3.40726  'A2.1' 10 30  9  7      7   1 >> 36    1  5  0.00000  'A2.1' 10 30  9  7      7   1 >> 37    1  1  0.00000 'MALE1' 10 30  9  7     12   1 >> 38    1  2  7.44743 'MALE1' 10 30  9  7     12   1 >> 39    1  3  3.53695 'MALE1' 10 30  9  7     12   1 >> 40    1  4  6.13176 'MALE1' 10 30  9  7     12   1 >> 41    1  5  9.03345 'MALE1' 10 30  9  7     12   1 >> >> >> So the loop is: >> >> DIST_LOOP<-matrix(NA,NA,ncol=11) >> >> for (i in 1:33){ >>        SEL_DAY<-seal_dist[seal_dist[,10]==i,] >>         SEL_DAY[i]=dist[i] >>         print(paste("DAY", i, "of 33")) >>        for (s in 1:11){ >>                        SEL_HR<-SEL_DAY[SEL_DAY[,5]==s,] >>        print(paste("HR", s, "of 11")) >>                indx <- subset(SEL_HR, SEL_HR\$DIST == 0) >>                SEL_HR\$TO_ID <- indx\$ID[match(SEL_HR\$TO, indx\$TO)] >>         DIST_LOOP[i,]<-SEL_HR >>        } >>        } >> >> But storing the data in the DIST_LOOP matrix doesn't work, I am just told >> in >> another post that a list might be better than a matrix? >> >> I hope this makes more sense!? >> >> Many thanks, >> >> Ross >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/storing-output-data-from-a-loop-that-has-varying-row-numbers-tp2238396p2238483.html>> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> [hidden email] 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. >> > > > > -- > Joris Meys > Statistical Consultant > > Ghent University > Faculty of Bioscience Engineering > Department of Applied mathematics, biometrics and process control > > Coupure Links 653 > B-9000 Gent > > tel : +32 9 264 59 87 > [hidden email] > ------------------------------- > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php> -- Joris Meys Statistical Consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control Coupure Links 653 B-9000 Gent tel : +32 9 264 59 87 [hidden email] ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php        [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 In reply to this post by RCulloch OK, then I was right. It's exactly what my code does. Enjoy. Cheers On Tue, Jun 1, 2010 at 4:25 PM, RCulloch <[hidden email]> wrote: > > Hi Joris, > > Thanks for your help! > > The data as requested: > > structure(list(FROM = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), >    TO = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, >    2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, >    3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), DIST = c(2.63981, >    0, 6.95836, 8.63809, 0, 2.63981, 8.03071, 8.90896, 8.90896, >    8.63809, 2.85602, 0, 8.03071, 6.95836, 0, 2.85602, 3.53695, >    4.32457, 0, 8.85851, 12.09194, 7.44743, 0, 4.32457, 13.16728, >    16.34761, 6.13176, 13.16728, 8.85851, 0, 3.40726, 9.03345, >    16.34761, 12.09194, 3.40726, 0, 0, 7.44743, 3.53695, 6.13176, >    9.03345), ID = structure(c(12L, 12L, 12L, 12L, 11L, 11L, >    11L, 11L, 14L, 14L, 14L, 14L, 13L, 13L, 13L, 143L, 12L, 12L, >    12L, 12L, 12L, 11L, 11L, 11L, 11L, 11L, 14L, 14L, 14L, 14L, >    14L, 13L, 13L, 13L, 13L, 13L, 94L, 94L, 94L, 94L, 94L), .Label = > c("'11.1'", >    "'15.1'", "'15.5'", "'18.1'", "'24.2'", "'26.1'", "'26.2'", >    "'28.3'", "'4.2'", "'7.1'", "'A1.1'", "'A1'", "'A2.1'", "'A2'", >    "'B1'", "'C1'", "'D1.1'", "'D1'", "'D2.1'", "'D2'", "'D3.1'", >    "'D3'", "'D4.1'", "'D4'", "'D5.1'", "'D5'", "'D6.1'", "'D6'", >    "'E1.1'", "'E1'", "'E2.1'", "'E2'", "'E4'", "'E5'", "'F1.1'", >    "'F1'", "'F10.1'", "'F10'", "'F11'", "'F2'", "'F3'", "'F4.1'", >    "'F4'", "'F5.1'", "'F5'", "'F7'", "'F8.1'", "'F8'", "'G2.1'", >    "'G2'", "'G3.1'", "'G3'", "'G4.1'", "'G4'", "'G5.1'", "'G5'", >    "'H1.1'", "'H1'", "'H2'", "'H3.1'", "'H3'", "'H8'", "'I1.1'", >    "'I1'", "'I2'", "'I4.1'", "'I4'", "'J1.1'", "'J1'", "'J2.1'", >    "'J2'", "'J3'", "'J6'", "'J7'", "'JUV'", "'K1.1'", "'K1'", >    "'K2'", "'K3'", "'K4.1'", "'K4'", "'L1.1'", "'L1'", "'L2.1'", >    "'L2'", "'L4'", "'M1'", "'M2.1'", "'M2'", "'M3.1'", "'M3'", >    "'M4.1'", "'M4'", "'MALE1'", "'N1.1'", "'N1'", "'N2'", "'N3'", >    "'N4.1'", "'N4'", "'O1'", "'O2'", "'O3.1'", "'O3'", "'O4.1'", >    "'O4'", "'O5'", "'P1.1'", "'P1'", "'Q1'", "'Q2'", "'Q3'", >    "'R1.1'", "'R1'", "'R2'", "'R3.1'", "'R3'", "'R4.1'", "'R4'", >    "'R5.1'", "'R5'", "'S1.1'", "'S1'", "'S2.1'", "'S2'", "'S3.1'", >    "'S3'", "'S4.1'", "'S4'", "'T1'", "'U1.1'", "'U1'", "'U2'", >    "'U3'", "'UKFEM'", "'UKMAL'", "'UKPUP'", "'V1.1'", "'V1'", >    "'W1.1'", "'W1'", "'WR'", "A2.1'"), class = "factor"), HR = c(9L, >    9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, >    10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, >    10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, >    10L), DD = c(30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, >    30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, >    30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, >    30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L), MM = c(9L, 9L, 9L, >    9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, >    9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, >    9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), YY = c(7L, 7L, 7L, 7L, 7L, >    7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, >    7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, >    7L, 7L, 7L, 7L, 7L, 7L), ANIMAL = c(1L, 1L, 1L, 1L, 7L, 7L, >    7L, 7L, 1L, 1L, 1L, 1L, 7L, 7L, 7L, 7L, 1L, 1L, 1L, 1L, 1L, >    7L, 7L, 7L, 7L, 7L, 1L, 1L, 1L, 1L, 1L, 7L, 7L, 7L, 7L, 7L, >    12L, 12L, 12L, 12L, 12L), DAY = c(1L, 1L, 1L, 1L, 1L, 1L, >    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, >    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, >    1L, 1L, 1L, 1L, 1L)), .Names = c("FROM", "TO", "DIST", "ID", > "HR", "DD", "MM", "YY", "ANIMAL", "DAY"), row.names = c(NA, 41L > ), class = "data.frame") > > > > The output should be as the original file is, but it should have an > additional column for 'TO_ID' > > I hope that makes sense? > > Cheers, > > Ross > > -- > View this message in context: > http://r.789695.n4.nabble.com/storing-output-data-from-a-loop-that-has-varying-row-numbers-tp2238396p2238576.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] 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. > -- Joris Meys Statistical Consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control Coupure Links 653 B-9000 Gent tel : +32 9 264 59 87 [hidden email] ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php        [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

Open this post in threaded view
|

Re: storing output data from a loop that has varying row numbers

 Hi Ivan, Thanks, Jorvis did answer the question - but good to know about list() and that matrix is no good for a mixture of output. I'm slowly getting my head around it!!!!! Thanks again for your help, it really was much appreciated! Ross