Displaying 20 results from an estimated 2000 matches similar to: "combinatorial programming problem"
2011 Apr 06
5
Need a more efficient way to implement this type of logic in R
I have cobbled together the following logic. It works but is very
slow. I'm sure that there must be a better r-specific way to implement
this kind of thing, but have been unable to find/understand one. Any
help would be appreciated.
hh.sub <- households[c("HOUSEID","HHFAMINC")]
for (indx in 1:length(hh.sub$HOUSEID)) {
if ((hh.sub$HHFAMINC[indx] == '01')
2012 Mar 16
3
Faster way to implement this search?
I am working on a simulation where I need to count the number of matches
for an arbitrary pattern in a large sequence of binomial factors. My
current code is
for(indx in 1:(length(bin.05)-3))
if ((bin.05[indx] == test.pattern[1]) && (bin.05[indx+1] ==
test.pattern[2]) && (bin.05[indx+2] == test.pattern[3]))
return.values$count.match.pattern[1] =
2010 Feb 22
1
shash in unique.c
Looking at shash in unique.c, from R-2.10.1 I'm wondering if it makes sense
to hash the pointer itself rather than the string it points to?
In other words could the SEXP pointer be cast to unsigned int and the usual
scatter be called on that as if it were integer?
shash would look like a slightly modified version of ihash like this :
static int shash(SEXP x, int indx, HashData *d)
{
2005 Sep 01
1
More block diagonal matrix construction code
Folks:
In answer to a query, Andy Liaw recently submitted some code to construct a
block diagonal matrix. For what seemed a fairly straightforward task, the
code seemed a little "overweight" to me (that's an American stock analyst's
term, btw), so I came up with a slightly cleaner version (with help from
Andy):
bdiag<-function(...){
mlist<-list(...)
## handle case in
2009 Sep 14
2
Escaping . in regular expression
If I run
cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f")
print(cvec)
indx<-grep('\.f',cvec,perl=TRUE)
fset<-cvec[indx]
print(fset)
I get
> cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f")
> print(cvec)
[1] "test.f" "test.sf"
2013 Apr 14
1
possible loop problem
Hi,
It would be better if you provided the output of dput(dataset).? I am not sure about the structure of your dataset.
Just from reading the data as is shown.
dat1<- read.table(text="
separator,tissID
>,>,2
,2,1
,6,5
,11,13
>,>,4
,4,9
,6,2
,7,3
,21,1
,23,58
,25,9
,26,4
>,>,11
,1,12
>,>,21
,4,1
,11,3
2017 Aug 09
2
Package nleqslv ERROR
Dear all,
I am relatively new to R and have had some difficulty in understanding an error i get when running a code to solve a system of non-linear equations, with four equations and two variables.
This is my code:
ALPHA <- c(-0.0985168033402, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4)
BETA <- c(-0.0985168033402, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4)
GAMMA <- c(0.3940672148378, 0.1, 0.15,
2008 Aug 16
1
unique.default problem (PR#12551)
Full_Name: Vilmos Prokaj
Version: R 2.7.1
OS: windows
Submission from: (NULL) (213.181.195.84)
Dear developers,
The following line of code (produced by a mistake) caused an infinite loop
unique("a",c("a","b"))
or also
unique(1,1:2)
I made a little investigation, and it seems to be that the following function
from unique.c is looping infinitely
static int
2017 Oct 12
4
comparing two strings from data
Hi,
I have two columns that contain numbers along with letters (as shown below)
and have different lengths. Each entry in the first column is likely to be
found in the second column at most once.
For each entry of the first column, if that entry is found in the second
column, I would like to get the corresponding index. For instance, if the
first entry of the first column is 5th entry in the
2013 Sep 26
1
Grouping Matrix by Columns; OHLC Data
HI,
May be this helps:
set.seed(24)
?mat1<- matrix(sample(1:60,30*24,replace=TRUE),ncol=24)
colnames(mat1)<- rep(c("O","H","L","C"),6)
indx<-seq_along(colnames(mat1))
n<- length(unique(colnames(mat1)))
?res<- lapply(split(indx,(indx-1)%%n+1),function(i) mat1[,i])
lapply(res,head,2)
#$`1`
#????? O? O? O? O? O? O
#[1,] 18 56 51 24 24 52
#[2,]
2017 Aug 09
0
Package nleqslv ERROR
Santi,
In the second line of your function you have the following:
f <- numeric(length(x))
This sets the length of this numeric vector (i.e., "f") to the length of the vector "x".
Later, inside the function you assign to values to 4 elements of the vector "f".
This assumes that "f" is at least 4 element in length.
However, you define
2010 Aug 13
1
loop for inserting rows in a matrix
Dear R friends,
I have a matrix with 2060 rows and 41 columns. One column is Date, another is Transect, and another is Segment. I want to ensure that there are 9 Transects (1 to 9) for each Date, and 8 Segments (1 to 8) for each Transect in the matrix, by inserting rows where these are missing.
I am new to coding, but am trying to write a loop which checks if each of the transects already
2012 Dec 11
1
Debian packaging and openblas related crash when profiling in R
Hello R-sig-debian and (hopefully) Dirk:
On Debian wheezy, I have the R packaging that CRAN (you) provide. I
run into a little trouble while trying to fiddle with alternative
BLAS.
I know you and I went around on this last year and I think perhaps
I've found something wrong in the framework, or I've just done
something wrong.
I installed the packages openblas-base and openblas-dev, and
2017 Oct 12
0
comparing two strings from data
It's generally a very good idea to examine the structure of data after you have read it in. str(data2) would have shown you that read.csv() turned your strings into factors, and that's why the == operator no longer does what you think it does.
use ...
data_2 <- read.csv("excel_data.csv", stringsAsFactors = FALSE)
... to turn this off. Also, the %in% operator will achieve
2017 Oct 13
1
comparing two strings from data
Combining and completing the advice from Greg and Boris the complete
solution is two lines:
data_2 <- read.csv("excel_data.csv", stringsAsFactors = FALSE)
match_list <- match( data_2$data1, data_2$data2 )
The vector match_list will have the matching position when it exists and
NA's otherwise. Its length will be the same as the length of data_2$data1.
You should get
2003 Sep 08
2
How do I coerce numeric factor columns of data frame to vector?
I have just noticed that quite a few columns of a data frame that I am
working on are numeric factors. For summary() purposes I want them to be
vectors. I tried, for example
> indx <- c(1:18,21:37,40,41)
> i <- 0
> i <- i+1
> summary(as.vector(sflows1[indx[i]]))
Length Class Mode
min.pkt.sz 3000 factor numeric
but this does not give the five-number
2011 Aug 12
1
Details of subassignment (for vectors and data frames)
Hi All:
I'm looking to find out a bit more about how subassignment actually works and am hoping someone with knowledge of the details can fill me in (I've looked at the source code, but my knowledge of C is lacking).
In the case of vectors, my reading of ?"[" would indicate that for a vector, vec <- 1:25, vec[c(1,5,25)] <- c(101,102,103)is functionally the same as
2008 Aug 22
1
Retrieving sample points
Hi everyone. My problem is about multivariate analysis. Given a multivariate data X, of dimension (n by p), n is the number of observations while p is the number of variables. I wanted a sample of size p+1 that will have its product of the eigen values of the covariance matrix to be the minimum among all the possible samples (n combination (p+1)). I have written a syntax with worked well, but the
2019 Dec 03
1
Dynamic load library problem using R 4.0.0
I'm having problems getting code that runs under 3.6.1 on MacOSX (and
Ubuntu)
to run the R version 4.0.0 on Windows. I have not tested R 4.0.0 on mac
(yet).
Key question: Has anything changed in R 4.0.0/Windows regarding how
dynamically loaded
libraries are accessed? Can someone please point me in the right direction?
WORKS On MacOSX Under:
R version 3.6.1 (2019-07-05) -- "Action of
2010 Sep 08
0
Correction to vec-subset speed patch
I found a bug in one of the fourteen speed patches I posted, namely in
patch-vec-subset. I've fixed this (I now see one does need to
duplicate index vectors sometimes, though one can avoid it most of the
time). I also split this patch in two, since it really has two
different and independent parts. The patch-vec-subset patch now has
only some straightforward (locally-checkable) speedups for