How to check if data frame exists in R environment?

时间:2017-04-06 17:10:14

标签: r dataframe

I am trying to add rows to a data frame if it exists, or assign it to initial data frame in case it doesn't exists. I have tried exists(), missing(), etc, but nothing is working for me.

exists(data) && is.data.frame(get(data))

Error in exists(data) : object 'data' not found

Any help would be highly appreciated. I am trying to do something like

if(exists(data))
    data <- rbind(data,new_data)
  else
    data <- new_data

1 个答案:

答案 0 :(得分:1)

If you read the documentation you’ll see that it says that exists requires

a variable name (given as a character string).

In other words, write:

exists('data') && is.data.frame(get('data'))
相关问题