【发布时间】:2020-06-30 21:43:33
【问题描述】:
我有一个数据集,其中每个变量都有多个版本。所有变量都以 _1、_2、_3 结尾。我想将变量的各种版本连接到一个新列中。我有一个非常大的数据集,所以我想尽量避免手动编码每个变量(例如 dat$test
test_1 test_2 test_3 type_1 type_2 type_3 other_1 other_2 other_3
a f f d s t j y b
s d c v s y h a m
d s v d h u n j k
我希望将变量表示在一个列中,如下所示:
test type other
aff dst jyb
sdc vsy ham
dsv dhu njk
我不熟悉循环,但我认为查找变量名然后将后续版本连接到新列中会涉及到 grep()?有没有人有建议去解决这个问题?任何帮助表示赞赏!
【问题讨论】:
标签: r loops variables concatenation