Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7742485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:17:16+00:00 2026-06-01T09:17:16+00:00

I need to create a data.frame that will be populated one row at a

  • 0

I need to create a data.frame that will be populated one row at a time by results of a for loop. It has 45 columns: the names of five of these are static but the remainder are read in (as a vector) from an external CSV file at run time. I’m looking for something along the lines of

goalsMenu <- read.csv("Phase 1 goalsmenu.csv", header = TRUE)
colHeads <- c("analysis","patient","date",as.vector(goalsMenu$Name),"CR")
output <- data.frame(colHeads)

however this creates a one-column data.frame with column name of colHeads.

colHeads <- list("analysis","patient","date",as.vector(goalsMenu$Name),"CR")

seems a step in the right direction but I need to “flatten” it to create the desired data.frame structure

could you advise please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:17:17+00:00Added an answer on June 1, 2026 at 9:17 am

    Does this help?

    goalsMenu <- paste("Name", 1:40, sep="")
    output <- as.data.frame(matrix(rep(0, 5 + length(goalsMenu)), nrow=1))
    names(output) <- c("analysis", "patient", "date", goalsMenu, "CR1", "CR2")
    

    Basically, I create a data.frame output with the number of columns first and name those columns in the next step. However, be aware about mdsumner’s comment! This way, all columns are of class numeric. You can deal with that later though: change the class of columns in data.frame

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a web service that returns XML data to some of
I need to create interface MultiLingual, that allows to display object's data in different
I have a .csv file containing 3 columns of data. I need to create
I need to create a pivot table in R that will have text values
i am new in Cassandra db. need help to create data model. i have
I need to create a new line of data within an array where the
I need to create an exact copy of data stored within a database. We're
I need to create an array from a list of data in excel. The
I need to create lines like this: <li data-target=c1.html><span>I. </span><span>Het tijdperk der goden</span></li> I
I need to create a json message like this: { success:true, count:3, data: [

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.