0 votes
1 view
in Data Science by (37.4k points)

For example, if I 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 do I combine the two columns n and s into a new column named x such that it looks like this:

  n  s   b x

1 2 aa  TRUE 2 aa

2 3 bb FALSE  3 bb

3 5 cc  TRUE 5 cc

1 Answer

0 votes
by (80.9k points)

You just have to 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...