I have a dataframe in R. Either the df has two columns with values, or it has the dimensions 0,0. If the dataframe has columns with values, I want to keep these values, but if the dimensions are 0,0, I want to create two columns with one row containing 0,0 values. Either it looks like this:
start = c (2, 10, 20)
end = c(5, 15, 25)
dataframe = as.data.frame (cbind (start, end))
-> if the df looks like this, it should be retained
Or like this:
start = c ()
end = c()
dataframe = as.data.frame (cbind (start, end))
-> if the df looks like this, a row with (0,0) should be added in the first row.
I tried ifelse
dataframe_new = ifelse (nrow(dataframe) == 0, cbind (start = 0,end =0) , dataframe)
But if the dataframe is not empty, it remains only the value of the first row and column. If the dataframe is empty, there is only one 0.