I have a data frame df with 2 columns, x and y.
x <- c("ABC", "def", "GHI")
y <- c("jkl", "MNO", "pqr")
df <- as.data.frame(cbind(x,y), stringsAsFactors = FALSE)
I'd like to add a column z, where the value of z = x if x is all uppercase, and z = y if x is all lowercase.
e.g. column Z in this example would be
ABC
MNO
GHI
The code that makes sense to me is the following:
df$z <- ifelse(identical(z$x, toupper(z$x)), z$x, z$y)
but this is just giving me a column z with the value "jkl" in each row.