DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Related

  • BigQuery DataFrames in Python
  • Five Fast JavaScript Data Grids — A Performance Review
  • Microservices with .NET Core: Building Scalable and Resilient Applications
  • Leveraging Apache Flink Dashboard for Real-Time Data Processing in AWS Apache Flink Managed Service

Trending

  • Boosting Efficiency: Implementing Natural Language Processing With AWS RDS Using CloudFormation
  • 12 Expert Tips for Secure Cloud Deployments
  • Leveraging Event-Driven Data Mesh Architecture With AWS for Modern Data Challenges
  • From Code to Insight: Using NLP and Sentiment Analysis in Git History
  1. DZone
  2. Data Engineering
  3. Data
  4. Learn R: How to Create Data Frames Using Existing Data Frames

Learn R: How to Create Data Frames Using Existing Data Frames

In this article, we go over several commands developers and data scientists can use to create data frames using existing data frames.

By 
Ajitesh Kumar user avatar
Ajitesh Kumar
·
Jun. 27, 15 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
253.0K Views

Join the DZone community and get the full member experience.

Join For Free

this article represents commands that could be used to create data frames using existing data frames . please feel free to comment/suggest if i failed to mention one or more important points. following is a list of command summaries for creating data frames by extracting multiple columns from existing data frame based on the following criteria, a sample of which is provided later in this article:

  • column indices
  • column names
  • subset command
  • data.frame command

6 techniques for a extracting data frame from existing data frames

the following commands have been based on the diamonds data frame which is loaded as part of loading the ggplot2 library.


head_diamonds

the following code shows how the diamonds data frame looks:

#1: create data frame with selected columns using column indices
# displays column carat, cut, depth
dfnew1 <- diamonds[,c(1,2,5)]

#2: create a data frame with the selected columns using column indices with sequences
# displays column carat, cut, color, depth, price, x
dfnew2 <- diamonds[, c(1:3, 5, 7:8)]

#3: create a data frame with selected columns using the data.frame command
# displays column carat, cut, color
dfnew3 <- data.frame(diamonds$carat, diamonds$cut, diamonds$color)
names(dfnew3) <- c("carat", "cut", "color")

#4: create a data frame using the selected columns and column names
# displays column carat, depth, price
dfnew4 <- diamonds[,c("carat", "depth", "price")]

#5: create a data frame using the subset command and column names
# displays column color, carat, price
dfnew5 <- subset(diamonds, select=c("color", "carat", "price"))

#6: create a data frame using the subset command and column indices
# displays column carat, cut, color, depth
dfnew6 <- subset(diamonds, select=c(1:3, 5))
Data (computing) Frame (networking) R (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • BigQuery DataFrames in Python
  • Five Fast JavaScript Data Grids — A Performance Review
  • Microservices with .NET Core: Building Scalable and Resilient Applications
  • Leveraging Apache Flink Dashboard for Real-Time Data Processing in AWS Apache Flink Managed Service

Partner Resources


Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: