Complete R Novice - Applying Logarithms to Dataset

Hi there,

Please forgive me if I've not posted this in the correct area. I've done some searches and not come across anything like my request below. Also, I don't think posting a reprex is relevant here - hope that's ok.

So, I've done some work in excel, but the dataset I'd like to apply a particular formula to is far too big, so trying my hand at R. I'm a complete R novice, and my R skills (so far!) just about extend to viewing datasets and using "count". Hopefully I'll be able to improve my R skills and one day give someone else R advice! For now though, I'm hoping someone will be able to give me advice with a request that might be slightly unconventional.

My dataset is a series of almost 3 million variables, each with a value between 0 and 30. For each variable, I'm trying to calculate Y, where Y is the number of times the value X needs to be doubled to get to 30. So to give some examples to help illustrate what I mean:

  • if X was 10, Y would be 1.5 (i.e. doubling once, then another half of a doubling - which I'm aware doesn't make complete sense written down!)
  • if X was 15, Y would be 1,
  • If X was 20, Y would be 0.5

This "doubling" methodology is based on available literature and research in the field I'm working on and is to give the effect of diminishing returns with each incremental increase (e.g. an increase from 1 to 2 is worth more than an increase from 29 to 30). I hope this makes some kind of sense.

My X values are numbers between 0 and 30, to varying numbers of decimal points.

The formula I used in excel to get the value I'm looking for is:
=LOG(30/X, 2)

Is there any way to apply this in R? If this can't be done, I'm considering rounding my values to whole numbers and then applying the Y figures as calculated for 1 to 30 in excel, but it'd be great if I can factor in the decimal points.

Any advice here would be really much appreciated!

Thanks,
Sean

x <- c(10, 15, 20)

y <- log2(30/x)
2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.