Anything Py(thon) Can Do…

Jason Eden
1 min readApr 8, 2021

Indexing / Slicing Operations in R

Another quick post: In my previous post I demonstrated a technique in Python programming that I have been using as part of my assignments for the Cornell University Machine Learning Certificate program. This got me to thinking: Can you do the same thing in R — i.e. subset a matrix based on a separate list of labels, and then perform operations on the subsets to populate another array of outputs?

Yes, yes you can, as I demonstrate here. It looks and feels a little different, but you can functionally accomplish the same thing. I did this as a quick exercise, so opted for a simple R script instead of RMarkdown. I’ll post screenshots of the output below, or you’re welcome to download and run it locally to see for yourself.

The way the output looks and the nomenclature are a little different, but similar enough to make sense.

Credit to Dr. Timothy Wiemken for answering a couple of sticky questions I was struggling with when trying to put this together.

--

--

Jason Eden

Data Science & Cloud nerd with a passion for making complex topics easier to understand. All writings and associated errors are my own doing, not work-related.