Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Learn R -- How to Get Data Frames Columns as Vectors

DZone's Guide to

Learn R -- How to Get Data Frames Columns as Vectors

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

This article represents different ways in which one could get a data frame column as a vector. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.

4 Techniques to Get Data Frame Column as Vector

In the examples below, diamonds dataset from ggplot2 package is considered. This is how a diamond dataset looks like:


head_diamonds

Following are four different technique/method using which one could retrieve a data frame column as a vector.

# In the data set shown above, carat represents column name and hence, [['carat']]
carat1 <- diamonds[['carat']]
# In the data set shown above, carat represents 1st column and hence, index 1
carat2 <- diamonds[,1]
# Pay attention to usage of dollar $ operator
carat3 <- diamonds$carat
# In the data set shown above, carat represents column name and hence, [, "carat"]
carat4 <- diamonds[,"carat"]




Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:
java ,bigdata ,framework ,tips and tricks ,r

Published at DZone with permission of Ajitesh Kumar. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}