Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #Create a list
  2. lst = [1,3,5,6,7,7]
  3. #index element at 4-2 (which is 2)
  4. lst[4-2] # returns 5
  5. #index element at 2-4 (which is -2) or lst[len(lst)-2]
  6. lst[4-2] # returns 7
  7.  
  8. lst <- c(1,3,5,6,7,7)
  9.  
  10. #indexing element at 4-2 (which is 2)
  11.  
  12. lst[4-2] # returns 3 (because R indexing starts at 1, not 0)
  13. [1] 3
  14.  
  15. #BUT indexing element at 2-4 (which is -2) does not work,
  16. #because it means that you are removing the element at index 2, i.e. 3
  17.  
  18. lst[2-4] #returns the original list without element at index 2
  19. [1] 1 5 6 7 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement