-3

I want to add a new column "Condition" based on the existing two columns, "target" and "response" and modify the contents in the new column to "target to response". But there is an error:

enter image description here

Please help! Thank you!

  • post data in text format – Onyambu Jun 21 '22 at 16:13
  • It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Please do not post code or data as images. Images cannot be indexed and searched nor copied into R for testing. – MrFlick Jun 21 '22 at 16:17

1 Answers1

1

It's better if you can paste reproducible data and code. Is this what you want to do, i.e. paste two columns?

library(tidyverse)

tribble(~col1, ~col2,
        "a", "b",
        "c", "d") |> 
  mutate(new_col = str_c(col1, col2, sep = " to "))

#> # A tibble: 2 × 3
#>   col1  col2  new_col
#>   <chr> <chr> <chr>  
#> 1 a     b     a to b 
#> 2 c     d     c to d

Created on 2022-06-21 by the reprex package (v2.0.1)

Carl
  • 4,232
  • 2
  • 12
  • 24