简体   繁体   English

如何合并数据框列中的值

[英]How to combine the values in a column of dataframe

I have a dataframe with two column. 我有两列的数据框。 I want to concatenate the values in a second column and return a string. 我想在第二列中连接值并返回一个字符串。 How can I do this in R? 我如何在R中做到这一点?

You can use paste with the appropriate delimiter. 您可以使用带有适当分隔符的paste Here, I am using '' . 在这里,我正在使用'' You can specify it to - , _ or anything else. 您可以将其指定为-_或其他任何名称。

 paste(df$Col2, collapse="")

If there are NAs you could use na.omit 如果有NAs ,则可以使用na.omit

 paste(na.omit(df$V2), collapse="")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM