List object not requiring unique names and only returning one instance of true

Hello,

I'd like to understand the following scenario. We are creating two lists where each has the name RT and yet when running the_list["RT"] it only returns the first one but not both?

> the_list <- c(list(RT=1),list(RT=5))
>
> the_list
$RT
[1] 1

$RT
[1] 5

> 
> the_list["RT"]
$RT
[1] 1

I am assuming the_list["RT"] is returning the first true value or returning false if it is not able to find any instance of true. I suppose my main question is - why is there nothing stopping the list object from accepting a new list with the same name as an existing one and then secondly if that is good intended behaviour why not have the_list["RT"] call show all instances of true?

Because R was not programmed so as to do that....your question is asking us to explain the mental process of Rs developers, that's out of scope for my abilities :slight_smile:

If there's any comfort I can give you it's that you aren't alone in questioning Rs approach.

Also, the takeaway lesson/moral from this is that duplicated names in lists should generally be avoided.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.