[R] storing output data from a loop that has varying row numbers
Ivan Calandra
ivan.calandra at uni-hamburg.de
Tue Jun 1 17:45:12 CEST 2010
Hi Ross,
I think Joris answered your question, but to keep with your own code:
To set up a list, you can use:
DIST_LOOP <- list()
Or, if you know the length:
DIST_LOOP <- vector(mode="list", length=11)
You would then fill up with (in your for loop):
DIST_LOOP[[i]] <- SEL_HR ##Actually, what you had at the beginning, but
DIST_LOOP is now a list so it should work.
Regarding what you're trying to do, wouldn't aggregate() work? Or with
unique()? I still haven't completely understood what you looking for, so
I might be completely wrong!
But as I said, I guess (and hope for you) Joris fixed the problem already
Ivan
Le 6/1/2010 16:56, RCulloch a écrit :
> 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
>
>
--
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
ivan.calandra at uni-hamburg.de
**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php
More information about the R-help
mailing list