首页 > 解决方案 > Tibble 和粘贴功能

问题描述

我尝试在小标题上使用粘贴功能,但我在下面得到了这个结果。我试图用 as.data.frame 对其进行转换,但结果是一样的。我真的需要使用 dplyr 来管理更大的数据集。

提前致谢。

Species=iris %>% select(Species)
paste("This is a ",Species)

[1] "这是 ac(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)"

标签: rdataframetidyversepastetibble

解决方案


这是我必须工作的解决方案。您可以使用 mutate 将字符串“This is a”与 Species 列粘贴在一起。我已将其保存为名为 which_species 的变量。

# Load tidyverse
library(tidyverse)

# Select Species from iris 
Species = iris %>% select(Species)
 
# I created a new variable pasting your string and the Species column together
Species <- Species %>% mutate(which_species = paste0("This is a ", Species))

# Check out the output
head(Species)

推荐阅读