w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
getActiveCell() always returns the upper left-hand cell, regardless of which cell is selected in the range
Yes you seem to be correct, the activecell in an active range is the one on the top left corner even if you selected the range from any of the other corners. What is your use case? function getCell() { var actvC = SpreadsheetApp.getActiveRange(); var txt_actvC = actvC.getA1Notation(); Logger.log(txt_actvC); actvC = SpreadsheetApp.getActiveSheet().getActiveCell(); txt_actvC = actvC.getA1Notation(); Logger.log(txt_actvC); } Result :

Categories : Google Apps Script

How to calculate useful upper and lower boundaries for a double value?
You can take this one (should work for your purpose): function ext_ceil(val){ if(val < 0) return 0; var str = val + ''; var arr = str.split('.'); var digitsLength = arr[0].length; var divisor = 1; if(val > 10){ for(var i=0;i<(digitsLength-1);i++){ divisor *= 10; console.log(divisor); } val = val / divisor; console.log(val); } val = Math.ceil(val); val *= divisor; return val; }; if you want to try this algorithm use my jsFiddle

Categories : Javascript

what is the average time, that an average process, running on an average kernel, using an average scheduler, gets in one active cycle?
Linux uses 100 milliseconds as the scheduler quantum, if that's what you were asking, in your own, convoluted way :-) There's nothing saying a process has to use their entire quantum and, in fact, if they release early, I think their priority gets bumped up a bit as a reward.

Categories : C

RadGridView Row value Updating, i'm entering value in one cell of row and it calculate and total figure should display in next row cell
you can write code inside the CellValueChanged event void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e) { if (e.Column.Name == "Val") { e.Row.Cells["Colname"].Value = (int)e.Value + 'someting'; } }

Categories : C#

Calculate average age of members (PHP)
Might be done with direct sql (using TIMESTAMPDIFF() and AVG() functions): SELECT AVG(TIMESTAMPDIFF(YEAR, `dob`, NOW())) as `average` FROM `member`;

Categories : PHP

Calculate the Average By Date
There are MANY ways to do this, but here's one way: =SUMPRODUCT(B1:B4,--(MONTH(A1:A4)=4),--(YEAR(A1:A4)=2013))/SUMPRODUCT(--(MONTH(A1:A4)=4),--(YEAR(A1:A4)=2013)) Of course, change the row numbers to match your data range

Categories : Excel

calculate average rating in php
It sounds like you want to use the AVG() http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html#function_avg

Categories : PHP

Calculate average using SSE with STL vectors
You're mixing float & double unnecessarily, especially as you don't let your accumulator be double your precision is totally destroyed and won't be close to satisfactory for larger series. As the arithmetic is super light weight what's destroying your performance here is most likely memory access, read up on memory cache lines and how they work. Basically what you need to do here is probe ahead, some processors have explicit instructions for pulling stuff into your cache, otherwise you can perform a load at a memory location ahead of time. Create another level of nesting in your loop and at regular intervals prime the cache with data you know you will get to in a few iterations. What people do to maximize performance is that they spend a lot of time actually designing their data lay

Categories : C++

Calculate average miles per gallon
You don't initialise your totals, so they are undefined. When you start adding to them, you get undefined results. I bet that's what you mean by it not working. Do this: double total_num1 = 0; double total_num2 = 0;

Categories : C

Calculate the average of all NSManagedObjects' attributes
I don't understand why you use a fetch results controller for this. A NSFetchedResultsController is not used for this. Use a simple NSFetchRequest for this. // Your previous code here // Execute the fetch. NSError *error = nil; NSArray *objects = [managedObjectContext executeFetchRequest:request error:&error]; if (objects == nil) { // Handle the error. } else { if ([objects count] > 0) { NSLog(@"Average price is: %@", [[objects objectAtIndex:0] valueForKey:@"averagePrice"]); } } A simple example of this can be found from Apple doc Fetching Specific Values.

Categories : IOS

Calculate the average of part of the image
You could use one of the imroi type functions in Matlab such as imfreehand I = imread('cameraman.tif'); h = imshow(I); e = imfreehand; % now select area on image - do not close image % this makes a mask from the area you just drew BW = createMask(e); % this takes the mean of pixel values in that area I_mean = mean(I(BW)); Alternatively, look into using regionprops, especially if there's likely to be more than one of these features in the image. Here, I'm finding points in the image above some threshold intensity and then using imdilate to pick out a small area around each of those points (presuming the points above the threshold are well separated, which may not be the case - if they are too close then imdilate will merge them into one area). se = strel('disk',5); BW = imdilate(I&g

Categories : Matlab

Calculate average from dates in text
Consider the following: Formulas: C2 = B2-A2 (same for rows 2 through 6) C7 = AVERAGE(C2:C6) D2 = INT(C2) & " Days " & TEXT(C2, "h:mm") & " hrs:min" (same for rows 2 through 7)

Categories : Excel

Calculate average hits with timestamps
For the average hits per day, you can just use the start timestamp. However, the exact syntax depends on whether you are using timestamp or unix_timestamp. For the first: select date(timestamp_start), count(*) from t group by date(timestamp_start) For unix_timestamp: select date(from_timestamp(timestamp_start)), count(*) from t group by date(from_timestamp(timestamp_start)) This does the grouping by day, represented as a date. Once you have it in that format, other functions, such as year(), month()anddate_format()` can be used for the other time periods.

Categories : PHP

SQL Most accurate way to calculate average increase
Basically, this is a math problem. Assuming q1=A, q2=B, q3=C and q4=D, then the difference is: B - A + C - B + D - C = - A + D = D - A Divide everything by 3 (3 differences), and you should get the same answer as Excel. Therefore, the query should be something like: SELECT StudentId, q1, q2, q3, q4, ((q4 -q1)/3) avgIncrease FROM gpaTable By the way, I am assuming in your example, that the StudentId is supposed to be different in the three lines above.

Categories : SQL

VBA calculate sum from active cell to its above cell values
To place the value in the activecell, using a loop try: Sub SumAboveLoop() Dim r As Range, rAbove As Range Dim v As Variant Set r = ActiveCell Set rAbove = Range(r.Offset(-1, 0), Cells(1, r.Column)) v = 0 For Each rr In rAbove v = v + rr.Value Next rr r.Value = v End Sub To place a value in the activecell without a loop, try: Sub SumAboveV() Dim r As Range, rAbove As Range Dim wf As WorksheetFunction Set wf = Application.WorksheetFunction Set r = ActiveCell Set rAbove = Range(r.Offset(-1, 0), Cells(1, r.Column)) r.Value = wf.Sum(rAbove) End Sub To place a formula in the activecell without a loop, try: Sub SumAboveF() Dim r As Range, rAbove As Range Dim wf As WorksheetFunction Set wf = Application.WorksheetFu

Categories : Vba

Use current cell value to calculate and replace in cell
Try something like this. First, make sure you have selected at least one cell, and then run the macro from the macros menu: Sub MultiplyBy30() Dim rng as Range Dim cl as Range Set rng = Range(Selection.Address) For each cl in rng.Cells If IsNumeric(cl.Value) And Len(cl.Value) > 0 Then cl.Formula = "=" & cl.Value & "*30" End If Next End Sub

Categories : Excel

Calculate the average of points in a array - Javascript
Try the following: function groupAverage(group) { var sum = 0; var count = group.length; for (var i in group) { sum += parseInt(group[i].split(',')[2], 10); } return sum / count; }

Categories : Javascript

Rails How to calculate average of several select boxes
You can access params in model. But usually params are accessed in controller. To solve your problem: First, create a column to save average, I assume your table is called grades: # generate migration file rails g migration add_average_to_grades average:float # update your database rake db:migrate Second, in your model calculate average with a callback: before_save :set_average def set_average self.average = [punctuality, attention ... ].sum / [punctuality, attention ...].size end Third, your controller should remain intact, something like: def create @grade = Grade.new params[:grade] if @grade.save # handle success else # handle grade not saved end end

Categories : Ruby On Rails

Calculate the average of several "time" commands in Linux
Like the commenter above mentioned, it sounds like you may want to use a loop to run your program multiple times, to get more data points. You can use the time command with the -o option to output the results of the time command to a text file, like so: time -o output.txt myprog

Categories : Linux

Python: Calculate the average of datetime with milliseconds
I'm not sure what result you are looking for. Does this suffice? import datetime as DT s1 = '00:02:25' s2 = '00:04:40' FMT = '%M:%S:%f' d1 = DT.datetime.strptime(s1, FMT) d2 = DT.datetime.strptime(s2, FMT) delta = (d2-d1)/2 mid = d1 + delta print(mid) yields 1900-01-01 00:00:03.325000

Categories : Python

Calculate average of 3 latest values in database
Try preselecting the values that you want in a subquery, and then averaging them (assuming that you are using a DBMS that employes the Limit keyword): Select Avg(tmp.Mood) From (Select Mood From reg order by CreateDate ASC Limit 3) as tmp

Categories : SQL

Calculate average of columns data in a matrix in R
I think you have yourself down a bit of a coding rabbit hole. You've got way too many functions in there that really aren't doing anything for you. You don't need print. You're trying to store a matrix into a matrix, without specifying meaningful/correct index values, etc. I'd really recommend taking a look at some introductory R texts to get familiar with indexing, which seems to be your main issue here. In much simpler terms, I think you just want something like: out <- sapply(3:ncol(mydata), function(i) { rowMeans(mydata[, c(i-2, i-1, i)], na.rm=TRUE) })

Categories : R

How to calculate 'single' average/mean value of pixels in a set ROI using cvAvg or mean?
My solution for computing the average of a single channel can be found in the following link: Average values of a single channel For your case, you have a ROI instead of a single channel. In OpenCV, an ROI is also a Mat object (if you are using OpenCV's C++ code) which you can pass to the cv::mean(...) function to get back a Scalar object. Only the first entry of that object will be set properly to the mean of your ROI and that is the value you want. See the link above for details.

Categories : Opencv

Using each member of class within one function to calculate average
It would be easier to store the scores in an array: #include <array> class Student { public: string firstName, lastName; std::array<int, 4> test; float average; }; Then you can easily get the average: #include <algorithm> // for std::accumulate Student s = ....; ... float avg = std::accumulate(s.test.begin(), s.test.end(), 1.0)/s.test.size();

Categories : C++

calculate average rating from mysql and show it as a graph
If you want all the averages in one query, you can just delimit them with commas. SELECT AVG(waiting), AVG(consultation), AVG(preoperative), AVG(specialists), ...... FROM feedback If you want to know how to put them in a graph, take a look at one of the many jQuery graph or plot makers, like: http://www.jqplot.com/tests/bar-charts.php

Categories : PHP

1-5 Star rating rank - How to calculate an average score
If you want a 1-10 scale, all you have to do is divide their total score by 2. So if they have 15 out of 20, that is equivalent to having 7.5 out of 10. >because 15/20 = 0.75 as does 7.5/10.

Categories : PHP

c# Linq remove duplicate items and calculate average values
var results = from kvp in source group kvp by kvp.Key.ToUpper() into g select new { Key= g.Key, Value= g.Average(kvp => kvp.Value) } or var results = source.GroupBy(c=>c.Name) .Select(c => new (c.Key, c.Average(d=>d.Value)));

Categories : C#

Calculate the average difference between two date columns for multiple rows
Use DATEDIFF() and AVG() select avg(datediff(view_date, sent_date)) from mails

Categories : PHP

Calculate average time difference between multiple unix timestamps
The most straight forward way it to do it like you described. $res =0; for($x = 1, $num = count($array); $x < $num; $x++){ $res =+ $array[$x] - $array[$x-1]; } echo $res/($num-1);

Categories : PHP

How to calculate average sensitivity and specificity at specified cutoff in ROCR package?
Actually, ROCR is an overkill for this task. The performance function of ROCR returns performance metrics at every score that is present in its input. So, theoretically you could do the following: library(ROCR) set.seed(123) N <- 1000 POSITIVE_CASE <- 'case A' NEGATIVE_CASE <- 'case B' CUTOFF <- 0.456 scores <- rnorm(n=N) labels <- ifelse(runif(N) > 0.5, POSITIVE_CASE, NEGATIVE_CASE) pred <- prediction(scores, labels) perf <- performance(pred, 'sens', 'spec') At this point perf contains a lot of useful information: > str(perf) Formal class 'performance' [package "ROCR"] with 6 slots ..@ x.name : chr "Specificity" ..@ y.name : chr "Sensitivity" ..@ alpha.name : chr "Cutoff" ..@ x.values :List of 1 .. ..$ : num [1:1001] 1 1 0.

Categories : R

Select messages, calculate the votes average and know if an user already have voted it
Try subquery select m.*, ( select count(1) from messages m1 where m1.id=m.id and m1.userid=@userid ) as VotedAlready, AVG(votes) as average_valuation from messages m group by m.id something like.. You can also add other query.

Categories : Mysql

How to calculate average of a column of numbers linked to each frequency bin making up a histogram, Excel 2010?
The question calls for a "wandering trace" of a scatterplot: the values of column A (plot them on the horizontal axis) are placed into bins, which therefore comprise vertical strips in the scatterplot. The values of column C (plotted on the vertical axis) are averaged within each strip. This technique smooths out and summarizes apparent trends in the scatterplot. In this example with 100 records the original data are in black and computed values are in green. Here is the wandering trace of means: The open circles plot column C (associated values) against column A (data) while the solid squares, connected with a dashed red trace, plot the bin means (column G) against the midpoints (column F). Any statistical package will provide functions for grouping data and performing operation

Categories : Excel

Add a class to a cell depending on data value
Add a function "fnRender": function(obj) { var sReturn = obj.aData[ obj.iDataColumn ]; if ( sReturn == "is wat you needed" ) { sReturn = "add style to your element"; } return sReturn; } Go through the example shown in below link http://datatables.net/examples/data_sources/js_array.html You can see that the A alphabet is bold compared to others..Hope this solves your problem

Categories : Javascript

R: changing value of a cell depending on two conditions
First create some data to play with: set.seed(1) L = c("A", "B", "C") dd = data.frame(x = sample(L, 10, TRUE), y = sample(L, 10, TRUE), z = 0) So dd is a data frame with three columns: R> head(dd) x y z 1 A A 0 2 B A 0 3 B C 0 4 C B 0 5 A C 0 6 C B 0 In the example below, if column x equals A and y equals C we should increase z by one: dd$z = dd$z + (dd$x == "A" & dd$y== "C") The key part is: (dd$x == "A" & dd$y== "C") which is a logical comparison and returns TRUE (1) or FALSE (0).

Categories : R

Calculate data in the same cell in Excel
Well, you will need to add macros to your sheet (Alt+F11 and double click your Sheet Name in Microsoft Excel Objects), and then something like this will solve your problem: Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) If Target = [E15] Then 'enters when cell E15 is modified Dim transactions transactions = [D15] Dim amount amount = [E15] Application.EnableEvents = False 'very important! Target.Value = amount - transactions * 0.1 - amount * (0.02) Application.EnableEvents = True Application.ScreenUpdating = False [E15].Activate 'select the same cell again Application.ScreenUpdating = True End If End Sub Be careful with Application.EnableEvents=False this deactivates the events so the formula will not get calcul

Categories : Excel

how to add a cell in a dynamic tableview section depending of a flag in objective-C
When sections change it resets indexPath. You are correctly identifying the number of rows but since both your registered and unregistered data are in the same array it is displaying the data at index 1 in the unregistered section. Thats why for a section with a row count of 1 it displays the data at index 1 of your array. You could fix this a number of ways. You could separate your data into a registered array and into an unregistered array. Or you can identify the correct index of the unregistered data and pass that to the objectAtIndexPath method. Also, IMHO your code would be a lot cleaner if you configured your cell in the method: - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { } instead of cellForRowAtIndexPath:

Categories : IOS

Clear Contents of Cell Range Depending on Background Color
You can apply the code below to all the cells in the given range: Dim targetIndex As Integer targetIndex = 16 'one grey If (ActiveCell.Interior.ColorIndex = targetIndex) Then ActiveCell.ClearContents End If You have to determine what you consider "grey". You might even include different indices just to make sure. Here you have a useful link with the indices associated with all the colours.

Categories : Vba

(Help) How To: Insert a HyperLink depending on how many characters have cell Using Google Script
Your script can be tweaked for better performance, by making use of the event data delivered to it instead of resorting to Service calls. You have done the right thing by testing for bail-out conditions early, but even those can be reordered to increase the chance of exiting early. function onEdit(e) { var activeCell = e.range; var activeCellValue = e.value; if (!e.value) return; // do nothing if value is 'undefined' var column = activeCell.getColumn(); var colNums = [1]; //Columns, whose edit is considered if(colNums.indexOf(column) == -1) return; //If column other than considered then return var row = activeCell.getRow(); if(row < 2) return; //If header row then return var length = String(activeCellValue).length; if(length == 12) { activeCell.set

Categories : Google Apps Script

How to Calculate specific cell total in SSRS?
It's hard to tell without seeing your DataSet/report, but the expression would be similar to: =Sum(IIf(Fields!Type.Value = "OPENING" or Fields!Type.Value = "PURCHASE" , Fields!qty.Value , Nothing) This will take a SUM of all qty values, but it will ignore any Type rows that don't match the types you're specifying, i.e. OPENING and PURCHASE. The most import thing is to make sure the expression is in the correct Scope, i.e. if you're grouping by Type the expression should be applied outside of that group Scope to make sure the expression is considering all the required rows.

Categories : SQL

How to calculate percentage for each cell in a dataframe using ddply?
No need for fancy packages. This will work as long as you want to do it to all but the first column. You could adapt the conditions for what columns are included if 2:ncol isn't appropriate. t(round(t(mydata[, 2:ncol(mydata)]) / colSums(mydata[, 2:ncol(mydata)]) * 100, 3)) And, since you asked about plyr and dplyr is the improved version of ddply, here's how you'd do it with that: require(dplyr) require(reshape2) mydata %.% melt(id.vars = "label") %.% group_by(variable) %.% mutate(prop = round(value / sum(value) * 100, 3)) %.% dplyr::select(-value) %.% dcast(label ~ variable, fun.aggregate = sum, value.var = "prop") Convert your data to long format, calculate the proportions, and switch it back to wide. A lot of typing for what Simon O'Hanlon shows to be a quick one-

Categories : R



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.