0

I try to add text to an existing text in a data.frame in R.

The text in the column is "icecream" and I want to add "_2017". The result should be "icecream_2017".

Can you help me solving this problem?

Thx a lot!

Max

P.S.: Please excuse the bad layout. Thats my first question in the forum.

  • It's easier to help you if you include a simple [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. – MrFlick Apr 09 '21 at 19:22

1 Answers1

3

Creating a data.frame matching your description:

ic_df <- data.frame(var = "icecream")

Using paste0() we can concatenate strings. paste0() is a convenience function, that concatenates strings with no separator.

ic_df$var <- paste0(ic_df$var, "_2017")
Till
  • 3,845
  • 1
  • 11
  • 18