I've been struggling to find a way to reprint the values of certain rows into a new column based on a specific condition. I have a data frame that looks like this:
Name V1 V2 V3
name1 a a1 yes
name2 b b1 yes
name3 c c1 no
name3 d d1 yes
I would like to create a new column using case_when or ifelse to reprint what is in the second column if V3 is yes, or add the first and second column if V3 is no. To look something like this:
Name V1 V2 V3 V4
name1 a a1 yes a1
name2 b b1 yes a1
name3 c c1 no c+c1
name3 d d1 yes d1
However, one issue Ive been running into is that my values are not all logical or all characters and are a mix of both. V3 are characters while V2 is a timestamp and V1 is a seconds time. I would appreciate any help. Thank you.
We can use
ifelsewithtransforminbase RIf these are not strings, then use
V1 + V2and remove thepaste0-ouput
NOTE: If the columns 'V2', 'V1' are of different class, convert both to
characterclass before doing theifelseOr using
dplyrdata