[R] simple subtraction in a single vector

jim holtman jholtman at gmail.com
Wed Feb 10 03:46:42 CET 2010


Not exactly sure what you are asking: is this it

> DF <- data.frame(length=c(1,2,3,4),
+ Tanks=c("a3","a4","c4","h4"))
> DF
  length Tanks
1      1    a3
2      2    a4
3      3    c4
4      4    h4
> DF$length[DF$Tanks == 'h4'] - DF$length[DF$Tanks == 'a3']
[1] 3
>


On Tue, Feb 9, 2010 at 9:37 PM, Marlin Keith Cox <marlinkcox at gmail.com> wrote:
> OK, this is very elementary, but I need help.  I have looked in Verzani,
> past postings etc.
>
> Problem:  I need to subtract the "length" date between "h4" and "a3"  #which
> would be 4-1
> I would rather not convert the two columns into four columns (with headings
> being "a3","a4","c4","h4").
>
>
> DF <- data.frame(length=c(1,2,3,4),
> Tanks=c("a3","a4","c4","h4"))
>
> ???
>
> Much appreciated, keith
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list