Similar questions have been asked about creating a column based on other columns. However, none seem to have a solution for my specific problem.
I am trying to create a new column that will be a mix of other columns and turned into a character. Hopefully my example below will explain what I mean.
If we have a data frame that looks like this:
dfTest <- data.frame( var = c("milk", "coffee", "honey", NA, "bread"), value = c(2 , 7, 1, 4, 10) ) > dfTest var value 1 milk 2 2 coffee 7 3 honey 1 4 <NA> 4 5 bread 10 What I want to do is create a new column that will be a mix of both var and value. Specifically if var is not NA then I want the new column to read: var ≤ value. And if var is NA, then I just want the the new column entry to be the value. For example, my new data frame would look something like this:
var value newCol 1 milk 2 milk ≤ 2 2 coffee 7 coffee ≤ 7 3 honey 1 honey ≤ 1 4 <NA> 4 4 5 bread 10 bread ≤ 10 Any suggestions as to how I could do this?