I have a variable c, and I want it to represent either data frame a or b depending on a condition. But I end up with a list instead of a data frame in R. How do I create an ifelse statement that can switch between two data frames?
a = data.frame(a = c(1:10), b = c(1:10))
b = data.frame(c = c(11:20), d = c(11:20))
g = 'testB'
c = ifelse(g == "testB", a, b)
Currently, c returns a list, but I just want a dataframe.
> c
[[1]]
[1] 11 12 13 14 15 16 17 18 19 20
> class(c)
[1] "list"
1