Adding the same substring to multiple columns in R

Asked

Viewed 91 times

2

I have a base with 2 lines and 68 remarks called "varnomes" and would like to add the word "PF" at the end of each remark. With that, I tried to use the function Paste:

varnomes<-paste(varnomes,"PF")

But I was unsuccessful.

The first three columns of my base are like this, for example:

a b c
g r v

And I want you to stay:

aPF bPF cPF
gPF rPF vPF

Any suggestions with apply or with another function?

2 answers

3

Try this:

df<-data.frame(var1=c("a","b","c"),var2=c("g","r","v"),stringsAsFactors=F)
df[]<-paste0(unlist(df[]),"PF")
  • 1

    Thank you, José! It worked with both answers, but unfortunately I have to choose one and I found Carlos' simpler.

3


Using the same basis df created by @José:

df[] <- lapply(df, paste0, "PF")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.