【发布时间】:2018-05-08 10:06:15
【问题描述】:
我已使用以下管道表达式加载了一个 .csv 文件、转换为 tbl、重命名变量、变异等:
h2020orgs <- read.csv2(file="C:/Users/Geoff/Desktop/Personal/DataCamp/R/R projects/Horizon_2020_orgs_data/cordis_h2020_orgs.csv") %>%
tbl_df() %>%
select(1:15) %>%
rename(projectRcn = ï..projectRcn,
orgType = activityType,
orgRole = role,
orgID = id,
orgName = name,
orgShortName = shortName) %>%
mutate(orgTypeFull = recode(orgType,
HES = "Higher education",
OTH = "Other",
PRC = "Private company",
PUB = "Public body",
REC = "Research centre"))
使用names(h2020orgs)可以看到变量的索引:
names(h2020orgs)
[1] "projectRcn" "projectID" "projectAcronym" "orgRole"
[5] "orgID" "orgName" "orgShortName" "orgType"
[9] "endOfParticipation" "ecContribution" "country" "street"
[13] "city" "postCode" "organizationUrl" "orgTypeFull"
我想移动“orgTypeFull”,使其与“orgType”相邻(紧接着)。我知道我可以使用以下独立调用来做到这一点:h2020orgs <- h2020orgs[, c(...)] 但有没有办法将它包含在上面的管道表达式中?
【问题讨论】: