[R-sig-teaching] reversing the scoring of some columns

Nicholas Horton nicholas_horton at yahoo.com
Thu Mar 16 15:04:46 CET 2017


Joel Schwartz wrote:

Cc: r-sig-teaching at r-project.org
Subject: Re: [R-sig-teaching] Reverse the scoring of some Columns of a
	Data	Set
Message-ID: <05A396B0-2AD4-4AD1-A27A-A9F9730BFC59 at joelschwartz.com>
Content-Type: text/plain; charset=utf-8

If your data frame is called df then you can reverse the scoring by doing df$x1 = rev(df$x1).

To do multiple columns, you can do:

df[ , paste0(?x?,1:3)] = lapply(df[ , paste0(?x?,1:3)], rev)


MY RESPONSE: Wow: that's a neat (but somewhat obfuscated) solution.  I make R and R programming a component of my upper level stats courses, but it's hard for me to imagine teaching all of the idioms that are embedded within it.  Are there cleaner ways to proceed?  How can we prepare students to be able to undertake wrangling of this sort?

Just my $0.02,

Nick



More information about the R-sig-teaching mailing list