Olamide Olumide
Olamide Olumide

Reputation: 11

naming elements of a list in R

I am new to R. I just started 2 days ago, I was following along with my instructor on the topic of naming list. I had seen an example done, and decided to do on my own.

list('Chicago' = 1, 'New York' = 2, 'Los Angeles' = 3)

$Chicago

Every time I run this code I keep getting the error message Error: unexpected '$' in "$" I was trying to print out 1, the numeric stored in Chicago

Upvotes: 0

Views: 45

Answers (1)

s_baldur
s_baldur

Reputation: 33498

You should assign your list to a name to access it again.

mylist <- list('Chicago' = 1, 'New York' = 2, 'Los Angeles' = 3)

mylist$Chicago
# [1] 1

Upvotes: 1

Related Questions