add

Expand data.frame by creating duplicates based on group condition (2)

℡╲_俬逩灬. 提交于 2019-12-02 09:38:24
Starting from @AndrewGustar answer/code: Expand data.frame by creating duplicates based on group condition 1) What about if I have the input data.frame with ID values not in sequence and that can also duplicate theirselves? Example data.frame: df = read.table(text = 'ID Day Count Count_group 18 1933 6 11 33 1933 6 11 37 1933 6 11 18 1933 6 11 16 1933 6 11 11 1933 6 11 111 1932 5 8 34 1932 5 8 60 1932 5 8 88 1932 5 8 18 1932 5 8 33 1931 3 4 13 1931 3 4 56 1931 3 4 23 1930 1 1 6 1800 6 10 37 1800 6 10 98 1800 6 10 52 1800 6 10 18 1800 6 10 76 1800 6 10 55 1799 4 6 6 1799 4 6 52 1799 4 6 133 1799

Byte typecasting in java

删除回忆录丶 提交于 2019-12-02 09:11:53
the program gives me loss of precision error but i cant think of any precision loss since numbers are small This is the code ## class Demo { public static void main(String args[]) { byte b1=3; byte b2=2; byte b3=b1+b2; System.out.println(b3); } } Jon Skeet The addition expression b1 + b2 is of type int - there aren't any addition operators defined on smaller types than int . So in order to convert that back to a byte , you have to cast: byte b3 = (byte) (b1 + b2); Note that although you happen to know that the values are small, the compiler doesn't care about the values you've set in the

Add ModelForm Fields as Attribute to Object

拈花ヽ惹草 提交于 2019-12-02 08:27:33
I have a ModelForm for my Risk set up as: class RiskForm(forms.ModelForm): class Meta: model = Risk fields = '__all__' def __init__(self, *args, **kwargs): progid = kwargs.pop('progid') super(RiskForm, self).__init__(*args,**kwargs) dict_of_fields = {} all_char = Program.objects.get(id=progid).char_set.all() for char in all_char: c = [] for cat in char.cat_set.all(): c.append( (cat.label, cat.label) ) dict_of_fields[char.label] = c self.fields[char.label] = forms.ChoiceField(c) Where the Risk Object is defined as: class Risk(models.Model): program = models.ForeignKey(Program, on_delete=models

Adding 2 std_logic_vector in variable type VHDL

痴心易碎 提交于 2019-12-02 08:22:41
I'm working in this school project. I have two std_logic_vector (31 downto 0) A and B, and I have a variable type std_logic_vector (32 downto 0) and I want to add A+B and put the result in my std_logic_vector with 32 bits. This is my design: library IEEE; use IEEE.STD_LOGIC_1164.ALL; USE ieee.numeric_std.ALL; use ieee.std_logic_arith.all; entity Ej3 is Port ( A : in STD_LOGIC_VECTOR (31 downto 0); B : in STD_LOGIC_VECTOR (31 downto 0); S : out STD_LOGIC_VECTOR (31 downto 0); AluOp : in STD_LOGIC_VECTOR (3 downto 0); COut : out STD_LOGIC; Z : out STD_LOGIC; OFL : out STD_LOGIC); end Ej3;

How to add arrays to ArrayList?

孤街浪徒 提交于 2019-12-02 07:26:46
I have an int[3][3] array and it contains only 0 or 1 values, if the value is 1 I want to add the coordinates of this value in the ArrayList as int[2] array, but I don't know why it always add the last 1-value coordinates, what's the problem? public static void main(String[] args) { Random random = new Random(); int[] coordinates = new int[2]; ArrayList<int[]> arrayList = new ArrayList<>(); int[][] board = new int[3][3]; for (int i = 0; i < board.length; i++) { for (int j = 0; j < board[i].length; j++) { board[i][j] = random.nextInt(2); } } for (int i = 0; i < board.length; i++) { for (int j =

Using listview in android

拈花ヽ惹草 提交于 2019-12-02 05:58:06
I am making an android application that needs to use a ListView . I want to add a menubutton that says "Add to list" and once the user presses that menubutton, it pops up a popupwindow containing a TextView , EditText and two Buttons , "Ok" and "Cancel". Once the user presses "Ok", the text inside the EditText should be added to the ListView . And the cancel Button is obvious. I also want to be able to long press on a ListView item to open a popupwindow containing a delete Button . I want to design the ListView screen using XML. How can i make this possible??? Please help me and thanks SO much

NSMutableArray addObjects - unrecognized-selector

荒凉一梦 提交于 2019-12-02 05:38:27
This is how I initialize my NSMutablearray. I copy the content of cityList into cityArray. Both are NSMutableArray. FYI, I declared the'cityArray' using extern. cityArray = [[NSMutableArray alloc] init]; [cityArray addObjectsFromArray:cityList]; Then, in other method in another class, I tried to to add one more object into 'cityArray' This is how I do it. But it keep crashing when it run this line of code. NSString *allCities = @"All Cities"; [[cityArray valueForKey:@"cityName"] addObject:allCities]; This is from the console '[__NSArrayI addObject:]: unrecognized selector sent to instance

Calculate time elapsed in php - spans over 24 hours

落爺英雄遲暮 提交于 2019-12-02 05:30:58
问题 What I am trying to do is add up hours/mins/secs that span over 24 hours, for example: 12:39:25 08:22:10 11:08:50 07:33:05 What I would like it to return is "39:43:30" rather than a date from 1970. Below is the code I'm currently using (note - its from within a class, not just a function). private function add_time($time1, $time2) { $first_exploded = explode(":", $time1); $second_exploded = explode(":", $time2); $first_stamp = mktime($first_exploded[0],$first_exploded[1],$first_exploded[2],1

(Update) Add index column to data.frame based on two columns

放肆的年华 提交于 2019-12-02 04:39:30
Example data.frame: df = read.table(text = 'colA colB 2 7 2 7 2 7 2 7 1 7 1 7 1 7 89 5 89 5 89 5 88 5 88 5 70 5 70 5 70 5 69 5 69 5 44 4 44 4 44 4 43 4 42 4 42 4 41 4 41 4 120 1 100 1', header = TRUE) I need to add an index col based on colA and colB where colB shows the exact number of rows to group but it can be duplicated. colB groups rows based on colA and colA -1 . Expected output: colA colB index_col 2 7 1 2 7 1 2 7 1 2 7 1 1 7 1 1 7 1 1 7 1 89 5 2 89 5 2 89 5 2 88 5 2 88 5 2 70 5 3 70 5 3 70 5 3 69 5 3 69 5 3 44 4 4 44 4 4 44 4 4 43 4 4 42 4 5 42 4 5 41 4 5 41 4 5 120 1 6 100 1 7 UPDATE

Swift NSMutableArray add one more array

北战南征 提交于 2019-12-02 04:17:16
问题 The Problem is First time I get data from WebServices so I have show this data on TableView Then user scroller down tableview then again call WebSevices and add this data to again in array but when I try to add data again in nsmutable type array app is crashing Here is my code. Any solution? 1st time Data load is Working var ary_mutable: NSMutableArray! ary_mutable = NSMutableArray() ary_mutable=jsonResult as AnyObject as! NSMutableArray self.tbl_T.reloadData(); self.tbl_T.delegate=self; self