Joel Schwartz wrote:

Cc: r-sig-teaching@r-project.org
Subject: Re: [R-sig-teaching] Reverse the scoring of some Columns of a
        Data    Set
Message-ID: <05a396b0-2ad4-4ad1-a27a-a9f9730bf...@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

_______________________________________________
R-sig-teaching@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-teaching

Reply via email to