score:15
Accepted answer
I would calculate changes between two consecutive numbers first. That can be done with Enumerable.Zip
of same list by skipping first item. Then you can get changes which are moving up or changes which are moving down and calculate their average:
var changes = list.Zip(list.Skip(1), (x,y) => y-x); // [ 2, 3, -6, -1, 4, -3 ]
var averageUp = changes.Where(x => x > 0).Average(); // 3
var averageDown = changes.Where(x => x < 0).Average(); // -3.33
Source: stackoverflow.com
Related Articles
- Comparing and allocating elements in Linq
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- Check which elements are on one list comparing to another list LINQ
- LINQ consider comparing elements by double
- Comparing code prior to LINQ
- source code for LINQ 101 samples
- LINQ query returning null when comparing elements in two lists
- Construct a list of wpf Hyperlink elements from an XML source file using Linq
- Select subset of elements by comparing them with each other in LINQ
- c# Linq or code to extract groups from a single list of source data
- C# Linq add elements from one list<custom> to another comparing them and changing values
- Using LINQ to remove elements from a List<T>
- Using Linq to get the last N elements of a collection?
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Apply function to all elements of collection through LINQ
- Determine if a sequence contains all elements of another sequence using Linq
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- Sequence contains no elements exception in linq without even using Single
- update multiple elements at once LINQ
- How to count the number of elements that match a condition with LINQ
- Linq UNION query to select two elements
- Comparing Arrays using LINQ in C#
- How to query an XDocument with LINQ when elements have a colon in their name?
- Match elements between 2 collections with Linq in c#
- Take the first five elements and the last five elements from an array by one query using LINQ
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- c# Linq query with Tuple List
- Entity Framework Code-First Aproach and ModelValidationException
- Linq to XSD processing
- How to bind data to DTO attribute based on a condition?
- MVC ViewModel Custom Property not populating if null exists
- Get parent object based on child of child criteria and include
- Is there a way to yield, emit or otherwise materialize a previously empty array in C# / LINQ?
- .NET LINQ Call Method with Out Parameters Within Query and use Out Values
- Pass linq anonymous object to function
- Linq query: append column to query results
- how to get the second level text from the leaf?
- Using split with \r\n\r\n
- IntelliSense dosen't give me option to select properties after implementing the LINQ
- C# Linq Expression could not be Translated
- Unable to cast object of type WhereSelectListIterator 2 System.Collections.Generic.List
- Select first unique child
- linq version of a query with let operator
- XMLSerializer to XElement
- Error When Adding Creating List From View
- skipWhile in LINQ is not working as excepted