【发布时间】:2021-12-05 08:18:04
【问题描述】:
如何根据 colname 模式创建多个重复列? 我的实际数据框非常大,所以我需要一个循环或其他一些高效的代码。
df <- data.frame(x001 = c(1,2,3), x002 = c(3,4,5), x003 = c(6,7,8), soccer = c(700,600,300), volley = c(30,22,29))
df
#current df
# x001 x002 x003 soccer volley
# 1 3 6 700 30
# 2 4 7 600 22
# 3 5 8 300 29
#desired output: all x00 columns need to be duplicated and get a "no2" addition to their name.
# x001 x002 x003 soccer volley x001no2 x002no2 x003no2
# 1 3 6 700 30 1 3 6
# 2 4 7 600 22 2 4 7
# 3 5 8 300 29 3 5 8
【问题讨论】:
标签: r loops dplyr duplicates tidyverse