Create blank data frame with R

This tutorial explains how to create a blank data set (data frame) with R.
 dummydt=data.frame(matrix(ncol=0,nrow=0))
Practical Application - It is very useful when you append data sets in a loop. In the first iteration, it is required to form a structure of the data frame so that data from the subsequent iteration can be added to it. Check out the code below.
unilogit2 = function(df,depvar, output) {
  dummydt=data.frame(matrix(ncol=0,nrow=0))  depvar1 = deparse(substitute(depvar))
  out = deparse(substitute(output))
  xxxx = names(df)[which(names(df)!= depvar1)]
  for (i in 1:length(xxxx)) {
  mylogit = glm(formula(paste(depvar1,"~",xxxx[i])), data = df, family = "binomial")
  coeff = data.frame(summary(mylogit)$coefficient)
  if (i==1) {output = rbind(dummydt,coeff)}  else {output = rbind(output,coeff)}  assign(out,output, envir = .GlobalEnv)
 }
ListenData Logo
Spread the Word!
Share
Related Posts
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he has worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and Human Resource.

13 Responses to "Create blank data frame with R"
  1. > dummydt=data.frame(matrix(ncol=0,nrow=0))
    > unilogit2 = function(df,depvar, output) {
    + dummydt=data.frame(matrix(ncol=0,nrow=0)) depvar1 = deparse(substitute(depvar))
    Error: unexpected symbol in:
    "unilogit2 = function(df,depvar, output) {
    dummydt=data.frame(matrix(ncol=0,nrow=0)) depvar1"
    > out = deparse(substitute(output))
    > xxxx = names(df)[which(names(df)!= depvar1)]
    Error in which(names(df) != depvar1) : object 'depvar1' not found
    > for (i in 1:length(xxxx)) {
    + mylogit = glm(formula(paste(depvar1,"~",xxxx[i])), data = df, family = "binomial")
    + coeff = data.frame(summary(mylogit)$coefficient)
    + if (i==1) {output = rbind(dummydt,coeff)} else {output = rbind(output,coeff)} assign(out,output, envir = .GlobalEnv)
    Error: unexpected symbol in:
    " coeff = data.frame(summary(mylogit)$coefficient)
    if (i==1) {output = rbind(dummydt,coeff)} else {output = rbind(output,coeff)} assign"
    > }
    Error: unexpected '}' in " }"
    >

    ReplyDelete
  2. Narcolepsy is the aftereffect of the concoction lopsidedness in the cerebrum and because of the insufficiency of protein called hypocretin in the mind. buymodafinilgeneric.com

    ReplyDelete
  3. The watches are grouped by brands, sexual orientation – looks for men and looks for ladies, costs, pair watches, and other such related classes. medicalclinicalresearch.net

    ReplyDelete
  4. Limited time messages about different items and administrations likewise contribute a huge factor towards web based advertising. tramadol-online.net

    ReplyDelete
  5. For me, it arrived in a digital book composed by Kacper Postawski. ambien-online.com

    ReplyDelete
  6. Deductibles can shift broadly from only a couple of hundred dollars to over $10,000 per year. my-tramadol.com

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Nice blog !! Thanks for sharing valuable information. Its quite different from other posts. Thanks for sharing.
    Check out the official website for order medicines online. www.tramadolrxusa.com/

    https://www.tramadolrxusa.com/
    https://www.tramadolrxusa.com/product/tramadol-100mg/
    https://www.tramadolrxusa.com/product/tramadol-50mg/
    https://www.tramadolrxusa.com/shop/
    https://www.tramadolrxusa.com/product/tapentadol-100mg/

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete

Next → ← Prev
Looks like you are using an ad blocker!

To continue reading you need to turnoff adblocker and refresh the page. We rely on advertising to help fund our site. Please whitelist us if you enjoy our content.