I am trying to seperate a column into multiple columns using tidyr. I tried initially using if..else and it wouldnt work and when I looked at stackoverflow the suggestion was to use ifelse. So I tried using ifelse and it still doessnt work. Below is what I am trying to do when I am getting the error :
testdata <- tibble::tribble(
~config, ~construct, ~var,
1, "This_is_line_1", 12,
2, "This_is_dot_2", 15,
3, "This_is_dot_1 ", 15,
4, "This_is_line_2", 12,
5, "This_is_line_3", 12,
6, "This_is_dot_4", 15,
7, "This_is_dot_3 ", 15,
8, "This_is_line_4", 12
)
ifelse(testdata$var == 12,
tidyr::separate(testdata$construct, into = c("etc1","etc2", "etc3","etc4"), sep = "_", remove = FALSE),
tidyr::separate(testdata$construct, into = c("etc1","etc2", "etc5","etc4"), sep = "_", remove = FALSE)
)
Error message : Error in UseMethod("separate_") : no applicable method for 'separate_' applied to an object of class "character"
Thank you.