Displaying 20 results from an estimated 10000 matches similar to: "why the a[-indx] does not work?"
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] =
2011 Jan 10
2
From vector to a step function
Greetings R members.
I have a few vectors that denote the 'steps' of different step functions
v1=c(3,4,5,1,2,3,4,5)
v2=c(5,6,2,4,7,3,2,5)
v3=c(1,2,4,7,3,1,3,5)
Here v1,v2,v3 are considered as the steps for the f1,f2,f3 step functions.
For example f1 looks like that (step size is always same and fixed)
f1= 3 (x>=-3,x<-2)
f1= 4 (x>=-2,x<-1)
f1= 5 (x>=-1,x<0)
f1= 1
2011 Sep 30
3
is member
Dear all,
I have a vector with number that some of them are part of the
seq(1,800,4). How can I check which of the numbers belong to the seq(1,800,4)
LEt's say that is called myvector the vector with the numbers.
Is there in R something like this?
is.member(myvector,seq(1,800,4))
I would like to thank you in advance for your help
B.R
Alex
[[alternative HTML version deleted]]
2012 Mar 19
3
where this Error comes from?
Dear all,
While I am executing my code I receive the error below
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
'x' must be atomic
the weird thing that I am not calling anywhere sort function nor do I rely on anyh sorting.
How I can discover where this comes from (inside which function?).
I would like to thank you in advance for your help
B.R
Alex
2011 Mar 04
4
How two compare two matrixes
Dear all I have two 10*10 matrixes and I would like to compare theirs contents. By the word content I mean to check visually (not with any mathematical formulation) how similar are the contents.
I also know edit that prints my matrix in the scree but still one edit blocks the prompt to launch a second edit() screen.
What is the best way to compare these two matrices?
I would like to thank you
2009 May 22
5
Need a faster function to replace missing data
Dear List,
I need some help in coming up with a function that will take two data sets, determine if a value is missing in one, find a value in the second that was taken at about the same time, and substitute the second value in for where the first should have been. My problem is from a fish tracking study. We put acoustic tags in fish and track them for several days. Location data is supposed
2011 Nov 03
2
optimising a loop
Dear R community,
I'm trying to remove a loop from my code but I'm stock and I can't find a good way to do it. Hopefully one of you will have something clever to propose.
Here is a simplified example:
I have a squared matrix:
> nom.plac2 <- c("102", "103", "301", "303","304", "403")
> poids2 <- matrix(NA, 6,6,
2013 Oct 11
3
matrix values linked to vector index
Hi,
In the example you showed:
m1<- matrix(0,length(vec),max(vec))
1*!upper.tri(m1)
#or
?m1[!upper.tri(m1)] <-? rep(rep(1,length(vec)),vec)
#But, in a case like below, perhaps:
vec1<- c(3,4,5)
?m2<- matrix(0,length(vec1),max(vec1))
?indx <- cbind(rep(seq_along(vec1),vec1),unlist(tapply(vec1,list(vec1),FUN=seq),use.names=FALSE))
m2[indx]<- 1
?m2
#???? [,1] [,2] [,3] [,4] [,5]
2013 Feb 14
2
Plot a Matrix as an Image with ggplot
Dear all,
I am trying to plot a matrix I have? as an image
str(matrixToPlot)
?num [1:21, 1:66] 0 0 0 0 0 0 0 0 0 0 .
?that contains only 0s and 1s,
where the xlabel will be Labeled as
str(xLabel)
?num [1:66] 1e+09 1e+09 1e+09 1e+09 1e+09 ...
and the yLabels will be labeled as
str(yLabel)
?num [1:21] -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 ...
I have found on the internet that I can do
2008 May 27
4
help with simple function
I have a matrix of frequency counts from 0-160.
x<-as.matrix(c(0,1,0,0,1,0,0,0,1,0,0,0,0,1))
I would like to apply a function creating a new column (x[,2])containing
values equal to:
a) log(x[m,1]) if x[m,1] > 0; and
b) for all x[m,1]= 0, log(next x[m,1] > 0 / count of preceding zero values
+1)
for example, x[1,2] should equal log(x[2,1]/2) = log(1/2) = -0.6931472
whereas x[3,2] should
2012 Mar 03
1
Sliding Window in R (solved)
Dear all,
you can find below my solution for sliding a window. Please find below the code for the two alternatives and the benchmarks.
install.packages('caTools')
require(caTools)
do_sliding_for_a_window_duty_cycle <- function(DataToAnalyse, windowSize) {
data<-DataToAnalyse
out <- numeric()
elements<- numeric()
if (length(data[,1]) >= windowSize){
for
2010 Sep 13
1
print matrix values and if statement
Hello everyone,
I have a 2x2 matrix filled with zeros and some more values around zeros. I would
like to print only the non-zero values
and
to keep the coords of the places that the values are not zero.
Could you please help me with that?
I would like to thank you in advance for your help
Best Regards
Alex
[[alternative HTML version deleted]]
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')
2013 Mar 22
3
Distance calculation
Hi Elisa,
I hope this is what you wanted.
dat1<-read.csv("peaks.csv",sep=",")
#Subset
dat2<-dat1[1:5,]
res1<-do.call(cbind,lapply(seq_len(nrow(dat2)),function(i) do.call(rbind,lapply(split(rbind(dat2[i,],dat2[-i,]),1:nrow(rbind(dat2[i,],dat2[-i,]))), function(x) {x1<-rbind(dat2[i,],x);
2012 Feb 21
2
Dataframes in PLS package
I have been working with the pls procedure and have problems getting the
procedure to work with matrix or frame data. I suspect the problem lies in
my understanding of frames, but can't find anything in the documentation
that will help.
Here is what I have done:
I read in an 10000 x 8 table of data, and assign the first four columns to
matrix A and the second four to matrix B
pls <-
2006 May 26
2
combinatorial programming problem
Hola!
I am programming a class (S3) "symarray" for
storing the results of functions symmetric in its
k arguments. Intended use is for association indices
for more than two variables, for instance coresistivity
against antibiotics.
There is one programming problem I haven't solved, making an inverse
of the index function indx() --- se code below. It could for instance
return the
2014 Mar 24
4
[PATCH 1/4] pm/fan: drop the fan lock in fan_update() before rescheduling
From: Martin Peres <martin.peres at labri.fr>
This should fix a deadlock that has been reported to us where fan_update()
would hold the fan lock and try to grab the alarm_program_lock to reschedule
an update. On an other CPU, the alarm_program_lock would have been taken
before calling fan_update(), leading to a deadlock.
We should Cc: <stable at vger.kernel.org> # 3.9+
Reported-by:
2017 May 31
4
stats::line() does not produce correct Tukey line when n mod 6 is 2 or 3
Seriously, if a method gives a wrong result, it's wrong. line() does NOT
implement the algorithm of Tukey, even not after the patch. We're not
discussing Excel here, are we?
The method of Tukey is rather clear, and it is NOT using the default
quantile definition from the quantile function. Actually, it doesn't even
use quantiles to define the groups. It just says that the groups
2012 Feb 04
1
Making a point-sampling matrix
Dear all,
I would like to create a k,n matrix which that will include
- k random elements with value 1
-all rest zeros
-one single "1" in each row
- each column will have maximum one "1"
so far I have a so stupid function that with nested while tries to fit k numbers randomly in a row by row fashion, checking also if the c column rule is violated. In that case there is
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