【发布时间】:2018-05-25 14:05:38
【问题描述】:
假设我必须关注数据
specialty <- c("Primary Care", "Internal Medicine Subspecialties" ,
"Pediatric subspecialties","Surgical subspecialties", "Emergency
Medicine","All other specialties", "No Medical specialty")
test <- c(23,43,67,77,54)
dfTEST <- data.frame(test)
dfTEST<- t(dfTEST)
colnames(dfTEST) <- c(1,2,4,5,7)
> dfTEST
1 2 4 5 7
test 23 43 67 77 54
请注意,我的 dfTest 有 5 个跳过数字的变量。我需要创建一个数据框,将这些 colname 数字 (1,2,4,5,7) 映射到专业。 Specialty 是与 dfTest colnames 协调的 7 个字符串。意思是dfTest 2 =“内科医学亚专业”和dfTest 4 =“外科亚专科等等。下面是我想要实现的目标的sn-p,但我不知道如何去做。我需要它灵活,因此无论列名中的数字是什么,代码仍然可以工作。有什么想法吗??谢谢!!
> dfTEST
1 2 4 5 7
test 23 43 67 77 54
added "primary care" "internal" ...
【问题讨论】: