Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (5.3k points)
edited by

I want to make the equivalent of a python dict in R. Basically, in python I have:

visited = {}

if atom_count not in visited:

  Do stuff

  visited[atom_count] = 1

The idea is, if I saw that specific, atom_count, I have visited[atom_count] = 1. Thus, if I see that atom_count again, I don't "Do Stuff". Atom_Count is an integer.

Thanks!

1 Answer

0 votes
by
edited by

For a dictionary in R, you can use the list data structure. You can set the names of the elements of a list using the names() function set equal to a vector of names.

For example:

l <- list(A = 5,B = "hello",C = 1:10)

> l

$A

[1] 5

$B

[1] "hello"

$C

 [1]  1  2  3  4  5  6  7  8  9 10

Related questions

0 votes
1 answer
asked Jul 10, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Oct 10, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 11, 2019 in Python by Sammy (47.6k points)

Browse Categories

...