broccoli

1

votes
3

answer
122

views

Perl regular expression extract array elements

I have a file with several rows of text. Each row contains a text array that is represented as follows ["ABC","D EF","XYZ"] ["MNO","P","QR ST"] ["A"] ... Notice, some of the words within quotes have spaces between them. I'm reading it into a perl script that looks like below while(){ @tmp = split /...
broccoli
1

votes
1

answer
613

views

R data.table applying a function to subset of columns based on parameters from a list

Assume I have the following data.table z = data.table(val1 = 1:11,val2 = 3:13). In addition to this, I have a list of parameters which looks as follows lambda = list(c(2,1),c(4,2)). What I'm trying to accomplish is to apply a transform to both columns of the data.table as follows val1 = val1^param1...
broccoli
1

votes
1

answer
131

views

R, Getting the top in every category from a data frame?

I have the following data frame id,category,value A,21,0.89 B,21,0.73 C,21,0.61 D,12,0.95 E,12,0.58 F,12,0.44 G,23,0.33 Note, they are already sorted by value within each (id,category). What I would like to be able to do is to get the top from each (id,category) and make a string, followed by the se...
broccoli
1

votes
2

answer
93

views

R, Using reshape to pull pre post data

I have a simple data frame as follows x = data.frame(id = seq(1,10),val = seq(1,10)) x id val 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 I want to add 4 more columns. The first 2 are the previous two rows and the next two are the next two rows. For the first two rows and last two...
broccoli
1

votes
1

answer
64

views

Blocking a shell script's execution flow until prior processes finish?

I've a list of jobs that I want to run in parallel and I call them all from one master script. Here is an example echo "Starting jobs" job1 & job2 & job3 & # I want to wait until job1, job2 & job3 finishes on the multi core box echo "Now I can proceed" How do I do this?
broccoli
3

votes
3

answer
892

views

Rake task executing twice when only called once

I've written a very simple rake task to try and locate the source of this problem. namespace :foo do task bar: :environment do puts 'RUNNING' end end When executed in the console rake foo:bar the output is: RUNNING RUNNING This occurs when I execute any rake task. Has anyone encountered anything lik...
Broc Broccoli
5

votes
3

answer
879

views

R generating a sparse matrix

I have a large file with the following format which I read as x userid,productid,freq 293994,8,3 293994,5,3 949859,2,1 949859,1,1 123234,1,1 123234,3,1 123234,4,1 ... It gives the product a given user bought and its frequency. I'm trying to make it into a matrix which gives all the productid's as co...
broccoli
1

votes
2

answer
336

views

Arduino Look-alikes and Ubuntu

I had a general question about coding with Arduino Uno-R3 on Ubuntu. I'm thinking of getting one ebay. I do see a lot of similar ones (not arduino branded) but at lower price. I intend to use it by plugging it into ubuntu 12.04 and fix some simple sensors on it. Do these non-branded "arduino"-like b...
broccoli
2

votes
1

answer
14k

views
1

votes
1

answer
1.5k

views

R data.table and kmeans clustering

I'm not even sure if this is possible with data.table. I have a data set that looks like the following. Its a data frame, but I later convert to a data.table, called x id xcord ycord a 2 3 a 3 4 a 3 3 a 9 10 a 8 9 b 1 3 b 1 2 b 8 19 b 7 21 I want to identify two clusters per id, and that is...
broccoli
1

votes
1

answer
271

views

R fitting a polynomial on data

I have some data synthetically generated from a function which is shown below. fn
broccoli
5

votes
2

answer
1.1k

views

Hashing function for mapping integers to a given range?

I've a set of integers each of which have 8,9 or 10 digits in size. I've millions of them. I want to map each one of them to an integer in the range of 1 to 1000. I cannot do a simple mod on the integers as there are systemic biases in the way these numbers have been issued (for example even numbers...
broccoli
4

votes
1

answer
1.3k

views

R ggplot2 fonts issue

I'm trying to get the xkcd fonts working in R with ggplot2. However I'm running into some issues. Here is what I have done so far. 1) Installed the "Humor Sans" font from the xkcd site in the directory ~/.fonts 2) Installed the "extrafont" package. This installation worked smoothly. 3) Load the libr...
broccoli
20

votes
6

answer
43.6k

views

Removing an item from an array in Objective-C

This question might seem easy, but I'm looking for the most efficient and memory friendly way. Let's say I have an array of Person objects. Each person has a hair color represented by an NSString. Let's then say I want to remove all Person objects from the array where their hair color is brown. H...
Choppin Broccoli
5

votes
3

answer
3.4k

views

Trapping signals cleanly in Perl

I have a simple Perl script that simply prints a line of text to stdout. What I want to accomplish is that while this script runs, if I (or someone else) issues a signal to that process to stop, I want it to trap that signal and exit cleanly. The code I have looks like the following #!/usr/bin/perl...
broccoli
2

votes
2

answer
219

views

Getting at grouping term from within ddply function?

I have the following example data frame x id val a 1 a 2 a 3 b 2 b 4 b 9 I have a simple function that I apply while doing my SAC. Something like, f.x
broccoli
2

votes
2

answer
783

views

Co-occurrence matrix using SAC?

I have the following data frame 'x' id,item,volume a,c1,2 a,c2,3 a,c3,2 a,c4,1 a,c5,4 b,c6,6 b,c1,2 b,c3,1 b,c2,6 b,c4,4 c,c2,5 c,c8,6 c,c9,2 d,c1,1 e,c3,7 e,c2,3 e,c1,2 e,c9,5 e,c4,1 f,c1,7 f,c3,1 The first column is the id of a customer, the second column is the id of an item that customer bought...
broccoli
4

votes
1

answer
106

views

Fast data.table filtering

I've a use case where I want to rapidly filter data tables repeatedly. I've a feeling that if I use a simple filter like df[val>0,] the scan is O(N), but if I simply set the val field as a key then I should be able to filter faster, but not sure how. As an example I've done the following a sorted da...
broccoli
2

votes
1

answer
404

views

R check sort order in two lists

This is turning out to be bit of a challenge. I've three vectors x, y & z x = c('a','b','c','d','f','m','n') y = c('b','c','f') z = c('b','a','n') x is my superset. It specifies the order in which the elements a,b,c... etc should appear. What I want to do is to be able to tell if a vector follows th...
broccoli
6

votes
3

answer
1.9k

views

R .C interface: Passing multidimensional arrays

I've written up a function "foo" in C that I want to call from an R program. The function takes in as input a matrix and does some operations on it, (say add 1 to each element). While it is easy to a single vector as .C("foo", n=as.integer(5), x=as.double(rnorm(5))) with foo implemented as void foo...
broccoli
12

votes
2

answer
4.3k

views

Pandas filling missing dates and values within group

I've a data frame that looks like the following x = pd.DataFrame({'user': ['a','a','b','b'], 'dt': ['2016-01-01','2016-01-02', '2016-01-05','2016-01-06'], 'val': [1,33,2,1]}) What I would like to be able to do is find the minimum and maximum date within the date column and expand that column to have...
broccoli
28

votes
2

answer
11.2k

views

Conditionally change panel background with facet_grid?

I'm using the "tips" data set in ggplot2. If I do sp = ggplot(tips,aes(x=total_bill, y = tip/total_bill)) + geom_point(shape=1) + facet_grid(sex ~ day) The plot comes out fine. But I now want to change the panel background for just the plots under "Fri". Is there a way to do this? Even better, ca...
broccoli
2

votes
1

answer
452

views

Request for declined permissions. Unity for Facebook

Been trying to request for declined permission with FB.login("Scope") but it redirects me to the login page again. After logging in, it prompts me with a "You have already authorised APPNAME." FB.login doesn't support "auth_type". Does anyone have any solutions to this problem? Thanks~ May the forc...
Dion Broccoli
1

votes
2

answer
78

views

R merging several contingency tables into one

I have the following list of contingency tables structure(list(`1` = structure(c(1L, 1L, 1L, 0L, 1L, 0L), .Dim = 2:3, .Dimnames = structure(list( c("a", "b"), c("x", "y", "z")), .Names = c("", "")), class = "table"), `2` = structure(c(1L, 1L, 0L, 1L), .Dim = c(2L, 2L), .Dimnames = structure(list(...
broccoli
1

votes
1

answer
77

views

@Injected @ManagedBean gets reinitialized despite of @ApplicationScoped annotation

I am writing a simple JSF application for converting currencies. There is a Rates class which holds the data, Currencies class for managing requests and Manage class for adding new currencies. My problem is: I want the currencies to be persisted as a property of Rates class hence my use of @Applica...
Broccoli
6

votes
6

answer
8k

views

In R, how do I locally shuffle a vector's elements

I have the following vector in R. Think of them as a vector of numbers. x = c(1,2,3,4,...100) I want to randomize this vector "locally" based on some input number the "locality factor". For example if the locality factor is 3, then the first 3 elements are taken and randomized followed by the next 3...
broccoli
2

votes
1

answer
362

views

Keras building a network for 9 dimensional feature vector

I have the following simple data set. It consists of 9 features and it is a binary classification problem. An example of the feature vectors are show below. Each row has its corresponding 0,1 label. 30,82,1,2.73,172,117,2,2,655.94 30,174,1,5.8,256,189,3,2,587.28 98.99,84,2,0.84,577,367,3,2,1237.34 3...
broccoli
2

votes
1

answer
2.4k

views

ggplot2 dotted lines for a subsection of a plot

I have the following data frame z = data.frame(x = seq(1,10),y = c(1,2,2,3,2,15,2,3,4,2)) To get a simple line plot is straight forward. For example this works. p = ggplot() + geom_line(data=z,aes(x,y)) I now want to call out the fact that the data point with value 15 is an outlier. To do this, I wo...
broccoli
2

votes
1

answer
2k

views

How to have SQL Server generate a sequential primary key?

When adding a new Entity Framework object to a database, how could one have SQL Server generate a sequential primary key for that object? Edit: Apparently by creating the table using a query which defines the primary key as IDENTITY (1, 1): CREATE TABLE TableName(ID int PRIMARY KEY IDENTITY (1, 1),...
broccoli_soup
2

votes
0

answer
160

views

How to mock a helper function in a PrivateObject

When testing private methods of a class using visual studio's built-in test tools one creates an instance of PrivateObject like so: PrivateObject classUnderTest = new PrivateObject(typeof(ClassUnderTest); Is it possible to have a method in that PrivateObject return set values for testing purposes l...
broccoli_soup
6

votes
4

answer
300

views

How can I multiply vectors without a loop?

I have two vectors: x = c(1,2,3) y = c(4,5,2) and I want to multiply each element of x with each element in y and then sum it all up. So what I want to do is something along the lines of: 1*(4 + 5 + 2) + 2*(4 + 5 + 2) + 3*(4 + 5 + 2) = 11 + 22 + 33 = 66 Is there a way to do it without loops? Thanks...
broccoli
3

votes
2

answer
325

views

R how to selectively sort a data frame?

I have the following example data frame in R. item index ptr A 1 0.40 B 2 NA C 3 0.30 D 4 0.35 E 5 0.44 F 6 NA It is already sorted based on column = index. Now, I would like to sort it by the column ptr but by leaving the position of rows where ptr = NA intact. So the...
broccoli
6

votes
2

answer
880

views

Uniqueness of NSPersistentStoreUbiquitousContentNameKey for iCloud and Core Data

In my app which allows users to sync the core data content across their multiple devices, how unique should I make the NSPersistentStoreUbiquitousContentNameKey? I.e. should it be unique in the sense of having the device ID? So if a user is running an app on their iPhone it has one NSPersistentStor...
Choppin Broccoli
3

votes
5

answer
160

views

Finding the 2nd max key of linked list?

Please help me fix my code. Some cases work but I believe cases like [9,1,2] would not work because the first number is the largest in that case. I am not sure how to fix that in my code. public Key secondMaxKey () { Node max = first; Node max_2nd = first; if (size() < 2) { return null; } for (Node...
broccoli lover
2

votes
1

answer
265

views

R sub select from a list of vectors using do.call, lapply or mapply?

I have the following data. x is a list of vectors and indices is a list of indices. x = list(c("a", "b", "c", "a"), c("b", "x", "a", "c")) indices = list(c(1, 2), c(3, 4)) What I want to do is step through each vector represented within the list x and sub select from that vector based on the indice...
broccoli
2

votes
0

answer
13k

views

Angular 2 http POST request

I'm new to Angular 2 and currently I'm trying to write a small web application and I'm kinda stuck. I need to do a post request and I have the following Python Code (I replaced the parameters here, but it works perfectly fine): import requests url = "https://somerandomlink.wasd" payload = "{\n \"...
Broccoli
1

votes
1

answer
91

views

How to sort a list of objects by a variable that is not part of the object?

Consider the following pseudo code: List People = new List(); int score; ... foreach (Person p in People){ score = scoreFunc(p); ??? } Question - how can I sort a list of Person objects by the score ? In case you are wondering, I would not want to make the score a property of Person because it will...
broccoli_soup
4

votes
1

answer
504

views

Interval search on a data frame

I've a data frame of time series and values. The time series are seconds from the epoch. Here is how the top few elements look like in that data frame val = seq(1,19) ts = seq(1342980888,1342982000,by=60) x = data.frame(ts = ts,val = val) head(x) ts val 1 1342980888 1 2 1342980948 2 3 1342981008...
broccoli
3

votes
3

answer
1.6k

views

R data.table finding the mode for a group of data

I have the following data table x id1 id2 a x a x a y b z For each combination of id1, id2 I can find the number of instances in the following way x[,list( freq = .N ),by = "id1,id2"] The above would yield a x 2 a y 1 b z 1 Next I want to find the most frequent id2 for each id1, i.e. mode. So th...
broccoli
1

votes
2

answer
1.6k

views

R print out matrix with row and column names using apply

I have the following matrix 'x' a b a 1 3 b 2 4 It is a really large matrix (trimmed down for this question) I would like to print out this matrix by each row name and column name combination along with the value in that cell. So the expected output would be a,a,1 a,b,3 b,a,2 b,b,4 I could loop thro...
broccoli

View additional