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]]
Tena koe Keith ?which perhaps. As in: which(Tanks=='h4')-which(Tanks=='a3') HTH ... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Marlin Keith Cox > Sent: Wednesday, 10 February 2010 3:37 p.m. > To: r-help at r-project.org > Subject: [R] simple subtraction in a single vector > > 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. >
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"))> DFlength 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?