predicate

R - Count numbers of certain values in each column

北城以北 提交于 2019-12-23 17:14:40
问题 I have found similar questions to mine, but none of them explains how to do that for each column of a dataframe. I have a dataframe like this: x1 = seq(12, 200, length=20) x2 = seq(50, 120, length=20) x3 = seq(40, 250, length=20) x4 = seq(100,130, length=20) x5 = seq(10, 300, length=20) df = data.frame(V1=x1, V2=x2, V3=x3, V4=x4, V5=x5) Now I want to get the number of values that are greater than 120 for each column. I have tried: nrow(df[,1] >120) That didnt work, it says 0, but its not true

Howto set a default condition with fieldname on ransack?

送分小仙女□ 提交于 2019-12-23 12:18:50
问题 I have a user and a roles model, both are associated via habtm and there is a forum model associated to roles. In ransack search form for forums i want to filter by users who have a specific role (by name: moderator). Source looks like this: class User < ActiveRecord::Base has_and_belongs_to_many :roles, :join_table => :users_roles rolify class Role < ActiveRecord::Base has_and_belongs_to_many :users, :join_table => :users_roles belongs_to :resource, :polymorphic => true class Forum <

NullPointerException at org.hibernate.ejb.criteria.path.AbstractPathImpl.get [duplicate]

和自甴很熟 提交于 2019-12-23 10:07:54
问题 This question already has answers here : JPA/Hibernate Static Metamodel Attributes not Populated — NullPointerException (8 answers) Closed 2 years ago . This works fine: public Predicate toPredicate(Root<Campaign> root, CriteriaQuery<?> query, CriteriaBuilder cb) { return root.get("campState").get("statusId").in(campStatus); } but I change to : return root.get(Campaign_.campState).get(CampState_.campId).in(campStatus). And it throws exception: edit for: NullPointerException at org.hibernate

How to prioritize/rank FilteredList results within a predicate?

余生长醉 提交于 2019-12-22 08:49:16
问题 My application contains a TextField and a ListView . The TextField allows users to enter search terms that will filter the contents of the ListView as they type. The filtering process will match several fields within each DataItem in the ListView and return the results if any of them match. What I want to do, however, is have those results prioritize items that match one particular field over the others. For example, in the MCVE below, I have two items: Computer and Paper . The Computer item

How do I create a set with std::pair thats sorted based on the ::second pair member using bind

北城余情 提交于 2019-12-22 08:28:55
问题 I know I could use the following: template <typename Pair> struct ComparePairThroughSecond : public std::unary_function<Pair, bool> { bool operator ()(const Pair& p1, const Pair& p2) const { return p1.second < p2.second; } }; std::set<std::pair<int, long>, ComparePairThroughSecond> somevar; but wondered if it could be done with boost::bind 回答1: How about the following one. I'm using boost::function to 'erase' the actual type of the comparator. The comparator is created using boost:bind itself

prevent window.onhashchange from executing when hash is set via JavaScript

十年热恋 提交于 2019-12-22 07:05:24
问题 I use the window.onhashchange function to execute code when the User changes the hash of the page: window.onhashchange = function() { /* do something */ }; In some functions I also set the hash via JavaScript: window.location.hash = "#abc"; I want to prevent the onhashchange event from firing when I set the hash via JavaScript. What I have tried so far: var currently_setting_hash = false; window.onhashchange = function() { if (currently_setting_hash) return; //... } currently_setting_hash =

Problem with `\+` in Prolog queries with variables

白昼怎懂夜的黑 提交于 2019-12-22 06:35:45
问题 I'm reading "Seven languages in seven weeks" atm, and I'm stumped over some Prolog query that I don't understand the 'no' response to. The friends.pl file looks like this: likes(wallace, cheese). likes(grommit, cheese). likes(wendolene, sheep). friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z). I can do some trivial queries on it, such as: | ?- ['friends']. compiling /home/marc/btlang-code/code/prolog/friends.pl for byte code... /home/marc/btlang-code/code/prolog/friends.pl compiled, 12

C# predicate list passed to Linq Where clause

流过昼夜 提交于 2019-12-22 04:36:11
问题 I have a long Linq Where clause that I would like to populate with a predicate list. List<Expression<Func<Note, bool>>> filters = new List<Expression<Func<Note, bool>>>(); filters.Add(p => p.Title != null && p.Title.ToLower().Contains(searchString)); filters.Add(p => p.Notes != null && p.Notes.ToLower().Contains(searchString)); filters.Add(GlobalSearchUser((List < User > users = new List<User>() { p.user1, p.user2, p.user3, p.user4 }), searchString)); notes = dataAccess.GetList<Note>(pn => pn

How to obtain index of element from predicate passed to some STL algorithm?

此生再无相见时 提交于 2019-12-21 09:14:03
问题 Say, I have vector of elements and a mask array, and I want to extract elements from vector with true corresponding mask value to separate vector. Is there a way to use std::copy_if for this purpose? The problem is, I only have value of element inside predicate, not iterator to it, so I cannot know the actual index to address mask array. I can directly manipulate addresses like this: vector<bool> mask; vector<int> a, b; copy_if(a.begin(), a.end(), b.begin(), [&] (int x) -> bool { size_t index

What is the difference between a lambda expression and a predicate in .NET?

ぐ巨炮叔叔 提交于 2019-12-21 03:30:57
问题 What is the difference between a lambda expression and a predicate in .NET? 回答1: A predicate is delegate (function object) that returns a boolean value. Lambda expressions can be used to define any anonymous function, which includes predicates, e.g. to express a predicate in the form of a lambda expression: Predicate<int> isEven2 = x => x % 2 == 0; which is functionally equivalent to: Func<int,bool> isEven = x => x % 2 == 0; 回答2: Predicate defines a set of criteria, while lambda expression is