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"?
            Asked
            
        
        
            Active
            
        
            Viewed 92 times
        
    -2
            
            
        - 
                    3Provide a reproducible example please – David Arenburg Apr 25 '14 at 10:44
- 
                    Maybe `names(sortList)[1]` - though it's unclear from your question – Gavin Kelly Apr 25 '14 at 10:53
1 Answers
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
