-2

I have the result of the sort function in R as the following: walk 23, facebook 21, news 20, net 17 Here it is showing every words with its corresponding frequencies. Suppose "sortList" is the variable name, and I am able to access the "facebook"'s frequency(23) by sortList[[1]]. How can I access the text "facebook"?

Sanjay Kumar N S
  • 4,653
  • 4
  • 23
  • 38

1 Answers1

3

Double brackets access the data in a specific list element (see The difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframe)
But if you are dealing with a named list e.g.

sortList = list(walk=23, facebook=21, news=20, net=17)

It's as easy as

sortList["facebook"]
$facebook
[1] 21

or to access the names the names() function.

names(sortList)
[1] "walk"     "facebook" "news"     "net"   
GWD
  • 1,387
  • 10
  • 22