I am collecting data from a number of different reports and some are using measurements on a different factor base.
So the vector looks like this:
a <- c("1.5", "1.8", "2.1", "3.4", "4100", "5.1", "6.3", "7.9", "8700", "8.9", "9.0", "11.7")
I'd like to divide the numbers which are greater than 100 by 1000.
Looking at another example I've tried
a[a>100] <- a/1000
But that doesn't seem to store the correct result. Any advice greatfully received.
What language you use for this?
In most dynamical language you can do something like this
a.map({ item -> if (item > 100) item / 1000 else item })
You need to adjust syntax, but generally it'll look like this.
Related
Problem =====>
Basically there are three .rrd which are generated for three departments.
From that we fetch three values (MIN, MAX, CURRENT) and print ins 3x3 format. There is a python script which does that.
eg -
Dept1: Min=10 Max=20 Cur=15
Dept2: Min=0 Max=10 Cur=5
Dept3: Min=10 Max=30 Cur=25
Now I want to add the values together (Min, Max, Cur) and print in one line.
eg -
Dept: Min=20 Max=60 Cur=45
Issue I am facing =====>
No matter what CDEF i write, I am breaking the graph. :(
This is the part I hate as i do not get any error message.
As far as I understand(please correct me if i am wrong) I definitely cannot store the value anywhere in my program as a graph is returned.
What would be a proper way to add the values in this condition.
Please let me know if my describing the problem is lacking more detail.
You can do this with a VDEF over a CDEF'd sum.
DEF:a=dept1.rrd:ds0:AVERAGE
DEF:b=dept2.rrd:ds0:AVERAGE
DEF:maxa=dept1.rrd:ds0:MAXIMUM
DEF:maxb=dept2.rrd:ds0:MAXIMUM
CDEF:maxall=maxa,maxb,+
CDEF:all=a,b,+
VDEF:maxalltime=maxall,MAXIMUM
VDEF:alltimeavg=all,AVERAGE
PRINT:maxalltime:Max=%f
PRINT:alltimeavg:Avg=%f
LINE:all#ff0000:AllDepartments
However, you should note that, apart form at the highest granularity, the Min and Max totals will be wrong! This is because max(a+b) != max(a) + max(b). If you dont calculate the min/max aggregate at time of storage, the granularity will be gone at time of display.
For example, if a = (1, 2, 3) and b = (3, 2, 1), then max(a) + max(b) = 6; however the maximum at any point in time is in fact 4. The same issue applies to using min(a) + min(b).
I've been trying to graph only for the past few hours. I only want to graph the TRUE arguments of this ifelse statement
which(RawGame1$event_desc == "Off Rebound")
reb <- ifelse(RawGame1$event_desc_id == "O",1,"")
Right now whenever I try to plot with ggplot, I get a bar graph where 13/22 bars are the 3rd argument(pointless data) that skews the scales and dimensions horribly. How do i delete them? Am i trying to graph it wrong?
ggplot(RawGame1[,], aes(x = pid.first.char, fill = reb)) +
geom_bar() +
ggtitle("Off Reb by Player") +
xlab("Player") +
ylab("Total Rebounds")
There has to be a simpler way i don't know about!?!? New to R and appreciate any help. Be gentle.
It would be much easier to answer if you provided a sample of your data (at least what head(RawGame1) prints out), also what the plot looks like now and what's the goal.
But I see that you have brackets without any filtering condition in RawGame1[,] - if you intended to select only event_desc_id=="0" there, just write RawGame1[RawGame1$event_desc_id==0,].
I'm am exploring methods of giving scores to different datapoints within a dataset. These points come from a mix of numbers and text string attributes looking for certain characteristics, e.g. if Col. A contains more than X number of "|", then give it a 1. If not, it gets a 0 for that category. I also have some that give the point when the value is >X.
I have been trying to do this with =IF, for example, =IF([sheet] = [Text], "1","0").
I can get it to give me 1 or 0, but I am unable to get a point total with sum.
I have tried changing the formatting of the text to both "number", "plain text", and have left it as automatic, but I can't get it to sum. Thoughts? Is there maybe a better way to do this?
FWIW - I'm trying to score based on about 12 factors.
Best,
Alex
The issue here might be that you're having the cell evaluate to either the string "0" or the string "1" rather than the number 0 or the number 1. That would explain why you're seeing the right things but the math isn't coming out right - the cell contents look like numbers, but they're really text, which the summation would then ignore.
One option would be to drop the quotation marks and write something like this:
=IF(condition, 1, 0)
This has the condition evaluate to 1 if it's true and 0 if it's false.
Alternatively, you could write something like this:
=(condition) * 1
This will take the boolean TRUE or FALSE returned by condition and convert it to either the numeric value 1 (true) or the numeric value 0 (false).
In my data frame there is a column with multiplier indicators, such as thousands, hundreds, millions, etc., as text.
I'd like to convert them to numeric. This is what I've tried:
a <- c("Thousands", "thousands", "Hundreds", "hundreds")
newA <- as.numeric(gsub("[Tt]housands","1000",gsub("[Hh]undreds","100",a)))
Which works, but results very cumbersome when there are many multipliers (as is the case). I was thinking there should be a way to do it in one gsub call, but wasn't able to do it. Something like this is what I would like (of course this particular attempt didn't work):
as.numeric(gsub("^.*-","",gsub("([Hh]undreds)([Tt]housands)","\\1-100 \\2-1000",a)))
Try:
library(qdap)
as.numeric(multigsub(c("[Tt]housands", "[Hh]undreds"), c(1000, 100), fixed = FALSE, a))
Or as per suggested by #RichardScriven:
library(stringi)
as.numeric(stri_replace_all_regex(a, c("[Tt]housands", "[Hh]undreds"), c(1000, 100),
vectorize_all = FALSE))
map(-30, -89.75, 89.75, 0, 360)
I'm looking for something like this where:
-30 is the input value.
-89.75 to 89.75 is the range of possible input values
0 - 360 is the final range to be mapped to
I was told there is a way to do this using http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-map
.. however its not readily apparent !
If I'm understanding correctly, I think you just want to uniformly map one range onto another. So, we just need to calculate how far through the input range it is, and return that fraction of the output range.
def map_range(input, in_low, in_high, out_low, out_high)
# map onto [0,1] using input range
frac = (input - in_low) / (in_high-in_low)
# map onto output range
frac * (out_high-out_low) + out_low
end
Also, I should note that map has a bit of a different meaning in ruby, and a more appropriate description would probably be transform.