Skip to content
Prev 387794 / 398502 Next

Looping through data error

Well, if I understand your query, wouldn't the following simple approach
suffice -- it assumes that the results for each company are ordered by
year, as your example seems to show:

## test is your example data
## first remove NA's
test2 <- na.omit(test)

## Now just use tapply():
+                       FUN =function(x)100 /x[1]))
1091347 11356069    22705 SC192761
12.28501 91.74312 15.26718 91.74312
## essentially a labelled vector
##You can use  %/% if you only want the whole number of shares that can be
purchased

It's somewhat messier if the results are not ordered by date within company
-- you could use by() and POSIXct to order the dates within company to get
the right one.

Cheers,

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Apr 13, 2021 at 11:34 AM e-mail ma015k3113 via R-help <
r-help at r-project.org> wrote: