I have a df with multiple columns that have many rows. I want to take one column and add single quotes around the values and a comma afterwards.
What I wanted it to look like:
For a single quote, sQuote can be used.
df1[,1] <- sQuote(df1[,1])
Or we can use sprintf to include the ' and the , afterwards
df1[,1] <- sprintf("'%d',", df1[,1])
If your column is df$x you would do:
df$x <- paste0("'", df$x, "',")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With