Skip to content
Back to formatted view

Raw Message

Message-ID: <08539cf0-1a49-1ac9-34e2-8006e8f90941@math.uni-giessen.de>
Date: 2021-03-24T16:52:38Z
From: Gerrit Eichner
Subject: Calculating column differences
In-Reply-To: <002b01d720cd$868cfc10$93a6f430$@sbcglobal.net>

Dear Jeff,

read diff's help page, and you'll find out
what is wrong with your expectation.

What do think diff(df$Score) should give for
the first element in df$Score??

  Hth  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
---------------------------------------------------------------------

Am 24.03.2021 um 17:48 schrieb Jeff Reichman:
> r-help forum
> 
>   
> 
> I'm trying to calculate the diff between two rows and them mutate the
> difference into a new column. I'm using the diff function but not giving me
> what I want.
> 
>   
> 
> df <- data.frame(ID=1:5,Score=4*2:6)
> 
>   
> 
> What a want  where
> 
>    ID Score  diff
> 
> 1  1     8      8
> 
> 2  2    12     4
> 
> 3  3    16     4
> 
> 4  4    20     4
> 
> 5  5    24     4
> 
>   
> 
> What I am getting
> 
>    ID Score  diff
> 
> 1  1     8      NA
> 
> 2  2    12     4
> 
> 3  3    16     4
> 
> 4  4    20     4
> 
> 5  5    24     4
> 
>   
> 
> Jeff
> 
>   
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>