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():
> out <-with(test
Rui, excellent diagnosis and suggestion. It worked but my damn logic is still
not delivering what I want-will spend more time on it tomorrow.
Kind regards
Ahson
> On 13 April 2021 at 17:06 Rui Barradas wrote:
>
>
> Hello,
>
> A close parenthesis is missing in the nd if.
>
>
> for (i in 1
Jim, thanks for taking the time to look into this. Yes, these if else
statements are so confusing.
I tried your amended scode and it does not work. The error are as follows:
Error: unexpected '}' in " }"
> NUMBER_OF_SHARES[i] = 100 / is.na(CLOSE_SHARE_PRICE[i])
> }
Error: unexpected '}' in " }"
Hello,
Typo, inline.
Às 17:06 de 13/04/21, Rui Barradas escreveu:
Hello,
A close parenthesis is missing in the nd if.
Should be "the 2nd if".
Rui Barradas
for (i in 1:(nrow(PLC_Return)-1)){
if (i == 1){
NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])
} else if(is.na(PLC
Hello,
A close parenthesis is missing in the nd if.
for (i in 1:(nrow(PLC_Return)-1)){
if (i == 1){
NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])
} else if(is.na(PLC_Return[i, 1]) == is.na(PLC_Return[i + 1, 1])){
NUMBER_OF_SHARES[i]=0
} else {
NUMBER_OF_SHARES[i] = 100
Your code was formatted incorrectly. There is always a problem with the
'else' statement after an 'if' since in R there is no semicolon to mark the
end of a line. Here might be a better format for your code. I would
recommend the liberal use of "{}"s when using 'if/else'
i <- 0
for (i in 1:(
Dear All,I have a dataframe with 4 variables and I am trying to calculate how
many shares can be purchased with £100 in the first year when the company was
listed
The data looks like:
COMPANY_NUMBER YEAR_END_DATE CLOSE_SHARE_PRICE NUMBER_OF_SHARES
2270530/09/200
7 matches
Mail list logo