Skip to content

Instantly share code, notes, and snippets.

@nilforooshan
Last active March 30, 2019 08:54
Show Gist options
  • Select an option

  • Save nilforooshan/531951a35d21127cd5e26358140c9ee1 to your computer and use it in GitHub Desktop.

Select an option

Save nilforooshan/531951a35d21127cd5e26358140c9ee1 to your computer and use it in GitHub Desktop.
R: Paste columns together in a new column

Paste columns together in a new column

A sample data:

(mydf = data.frame(w = 1:3, x = c('a','b','c'), y = c('d', 'e', 'f'), z = c('g', 'h', 'i')))
  w x y z
1 1 a d g
2 2 b e h
3 3 c f i

Example:

(mydf$zz <- apply(data[,2:4], 1, paste, collapse = ""))
  w x y z  zz
1 1 a d g adg
2 2 b e h beh
3 3 c f i cfi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment