r - How to combine two or more columns in a dataframe into a new column with a new name? -


for example if have this:

n = c(2, 3, 5)  s = c("aa", "bb", "cc")  b = c(true, false, true)  df = data.frame(n, s, b)    n  s     b 1 2 aa  true 2 3 bb false 3 5 cc  true 

then how combine 2 columns n , s new column named x such looks this:

  n  s     b     x 1 2 aa  true  2 aa 2 3 bb false  3 bb 3 5 cc  true  5 cc 

use paste.

 df$x <- paste(df$n,df$s)  df #   n  s     b    x # 1 2 aa  true 2 aa # 2 3 bb false 3 bb # 3 5 cc  true 5 cc 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -