r - dplyr on subset of columns while keeping the rest of the data.frame -
i trying use dplyr apply function subset of columns. however, in contrast code per below, trying implement while keeping columns in data-frame. currently, resulting data-frame keeps selected columns. can use remove-and-cbind construction merge these columns original dataframe, wondering if there way directly in dplyr? have tried move select function inside mutate function, not able make work yet.
require(dplyr) replace15=function(x){ifelse(x<1.5,1,x)} dg <- iris %>% dplyr::select(starts_with("petal")) %>% mutate_each(funs(replace15)) dg > dg source: local data frame [150 x 2] petal.length petal.width 1 1.0 1 2 1.0 1 3 1.0 1 4 1.5 1 5 1.0 1 6 1.7 1 7 1.0 1 8 1.5 1 9 1.0 1 10 1.5 1
dg <- iris %>% mutate_each(funs(replace15), matches("^petal"))
alternatively (as posted @aosmith) use starts_with
. have @ ?select
other special functions available within select
, summarise_each
, mutate_each.
Comments
Post a Comment