Slicing and selection

In R, we slice objects in the following three ways:

  • [: This always returns an object of the same type as the original and can be used to select more than one element.
  • [[: This is used to extract elements of a list or DataFrame, and can only be used to extract a single element. The nature of the returned element will not necessarily be a list or DataFrame.
  • $: This is used to extract elements of a list or DataFrame by name and is similar to [[.

Here are some slicing examples in R and their equivalents in pandas:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset