[R-sig-teaching] Reverse the scoring of some Columns of a Data Set
Joel Schwartz
joel at joelschwartz.com
Wed Mar 8 18:02:55 CET 2017
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)
> On Mar 8, 2017, at 8:34 AM, AbouEl-Makarim Aboueissa <abouelmakarim1962 at gmail.com> wrote:
>
> Dear All: goods morning
>
> Sorry if this topic does not match with the r-sig-teaching group.
>
>
> Is there is a way to reverse the scoring of the first three columns x1, x2,
> and x3 and keep the original scores for the fourth column x4.
>
>
> *Here is an example of the data set:*
>
> x1 x2 x3 x4
> 2 5 4 4
> 1 1 1 6
> 1 2 1 6
> 2 3 2 4
> 1 2 1 6
> 1 3 1 6
> 2 2 2 5
> 2 1 1 6
> 2 2 4 5
> 5 5 2 1
>
> I am expecting the output to be:
> x1 x2 x3 x4
> 5 5 2 4
> 2 2 4 6
> 2 1 1 6
> 2 2 2 4
> 1 3 1 6
> 1 2 1 6
> 2 3 2 5
> 1 2 1 6
> 1 1 1 5
> 2 5 4 1
>
>
>
> thank you very much for your help and support
> abou
>
> ______________________
> AbouEl-Makarim Aboueissa, PhD
> Department of Mathematics and Statistics
> University of Southern Maine
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-teaching at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
More information about the R-sig-teaching
mailing list