[R] storing output data from a loop that has varying row numbers

RCulloch ross.culloch at dur.ac.uk
Tue Jun 1 16:56:41 CEST 2010


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

-- 
View this message in context: http://r.789695.n4.nabble.com/storing-output-data-from-a-loop-that-has-varying-row-numbers-tp2238396p2238630.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list