r - Simultaneously subsetting and operating on a specific column of a data frame -


let's have data.frame df

df<-data.frame(a=1:5,b=101:105,c=201:205) 

can call subset of data while simultaneously performing kind of modification (e.g., arithmetic) 1 of columns (or rows) on fly?

for example, if want return first , second column of df return log of column 1 values. there notation modify df[,1:2] produce following on fly?:

              b >1  0.0000000 101 >2  0.6931472 102 >3  1.0986123 103 >4  1.3862944 104 >5  1.6094379 105 

this example within()

within(df[1:2], <- log(a)) #             b # 1 0.0000000 101 # 2 0.6931472 102 # 3 1.0986123 103 # 4 1.3862944 104 # 5 1.6094379 105 

or if prefer not have <- in call, can use brackets

within(df[1:2], { = log(a) }) 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -