I'm trying to dynamically create and assign values to variables of a particular data frame using a for loop. I want to create the object from an array of strings, add the word "Check" to the end, then continue assigning it. The problem is, I'm having trouble referring to the variable as an element of an object.
Probably easier to show than explain....
diffs$derp = c("this", "that", "the other")
diffs$herp = c("esa", "esto", "el otro")
for(i in ncol(derp)) {
temp = paste0(derp[i], "Check")
diffs$temp = ifelse(derp[i] == derp[i], "Equal", paste(derp[i], herp[i], sep=" =/= "))
}
The problem of course is that this code thinks that I'm referring to a variable in diffs
called temp
. I've seen the assign()
function, but I don't see a way to add my new variable to a data frame with it.
EDIT: I'd like to get output like:
diffs$thisCheck = ifelse(diffs$this == diffs$that, "Equal",
paste(diffs$this, diffs$that, sep=" =/= "))