Displaying 20 results from an estimated 10000 matches similar to: "Consecutive zeros in a vector"
2013 Apr 11
2
(no subject)
Dear all,
Is there a quick and easy way of converting utf characters to the \uxxxx
form (necessary e.g. for packages)? I mean something working like this:
> utf2uxxxx("õäöü")
[1] "\u00f5\u00e4\u00f6\u00fc"
It is easy to program but perhaps someone already has implemented this. (I
couldn't find anything useful from searches incl RSiteSearch).
Thanks in advance,
Kenn
2011 Mar 03
1
sqlFetch (RODBC) question
Dear all,
I've used RODBC a lot to read in files created in MS excel and access but
found a strange problem today: a variable in my data file contained both
numbers and text; sqlFetch would set text within a row of numbers to NA; but
if first 5 or 6 rows would be text then all numbers would be read in as NA.
con<-odbcConnectExcel("xample.xls") #the file is attached or at
2011 Mar 25
2
Preserving the class of POSIXt objects
Dear all,
I am working with a list of objects each of which contains two POSIXct
objects (say, $Start and $End) and a number of different data in
addition to that. Now an easy way to extract Start times of all object
could be sapply(x, "[", "Start") but this converts them all to
numeric, and so does sapply(x, "[[", "Start"). lapply preserves the
class but
2011 Apr 10
4
Password-protect R script files
There was a question in R forum very long time back.. on how to protect R
Script files from inadvertent editing by users.
There is a way to do this from within R, atleast in Windows XP I have tried
this and it certainly works , The method is very different from the OS
based folder protection route, however making available such a method in
the open forum would only kill the very spirit of R.
2011 Oct 12
1
exclude columns with at least three consecutive zeros
Hi everyone,
I have a large data set with about 3'000 columns and I would like to exclude
all columns which include three or more consecutive zeros (see below
example). A further issue is that it should just jump NA values if any. How
can I do this?
In the below example R should exclude column C and D (since in D jumping the
NA leaves three consecutive zeros).
I would appreciate
2011 Mar 21
1
Curry with `[.function` ?
Dear all,
I sometimes use the following function:
Curry <- function(FUN,...) {
# by Byron Ellis,
https://stat.ethz.ch/pipermail/r-devel/2007-November/047318.html
.orig <- list(...)
function(...) do.call(FUN,c(.orig,list(...)))
}
... and have thought it might be convenient to have a method for [ doing
this. As a simple example,
> apply(M, 1, mean[trim=0.1]) # hypothetical
2007 Oct 12
2
Q-type factor analysis
Hallo!
Is there a package in R that does Q-type factor analysis?
I know how to do principal component analysis, but haven't found any application of Q-type factor analysis.
Thx,
Julia
--
Psssst! Schon vom neuen GMX MultiMessenger geh?rt?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
2012 Mar 08
3
Calculating length of consecutive sequences within a vector
Hi all,
I have a nx1 logical array of zeros and ones and I want to calculate the individual lengths of all 1-consecutive sequences contained in it. Is there an easy quick way to do this in R? So, if I have a vector such as
111001101000011111110
I would like to get (1) 3, (2) 2, (3) 1, (4) 7
Any help would be appreciated! thanks!
Jorge
[[alternative HTML version deleted]]
2011 May 04
4
Recursive objects
Hi all,
Does anyone have a comprehensive list of recursive-type objects in R?
is.recursive defines them as by exclusion: "most types of objects are
regarded as recursive, except for vector types, ?NULL? and symbols
(as given by ?as.name?)." I think this that means recursive objects
are:
* lists
* pairlists
* calls
* expressions
Did I miss anything?
Hadley
--
Assistant
2011 Jan 06
2
Global variables
Dear R-users,
Is there a way I can prevent global variables to be visible within my
functions?
Sebastien
2009 Oct 28
1
Need help locating the longest series of consecutive numbers in a matrix
I need to determine the length of the longest series of consecutive numbers
(1's to be specific) and the start time of that series. For example, in the
following sample, the first column is "time" and the second column indicates
the presence of the target behavior.
I would like a function that would return "21" as the start time and "17" as
the length.
sample
2009 Oct 29
1
How to turn individual consecutive information into survival objects?
Dear R List,
I have a dataset with the following structure:
"""personal_id, p_0, p_1, p_2, .... , p_36, p_37
1, NA, 1, 4, .... , 1, NA
2, NA, NA, NA, .... , 4, NA
.
.
.
6020, NA, 3, 3, ...., NA, NA
6021, NA, 2, 2, ...., 4, NA
"""
I used some made-up data. It is just meant to show the structure of the dataset.
The variables of interest are p_0, ... p_37.
2011 Feb 02
2
Help me apply mapply
Hello all I would like to ask your help use mapply.
I have a function called findCell that takes two arguments(x,sr)
where x is a vector of size two (e.g x<-c(2,3) and sr is a matrix.
I would like to call many times the findCell function (thus I need mapply) for different x inputs but always for the same sr.
as x is a vector of size two (two cells) I want to pass inside inside the following
2008 May 13
2
Max consecutive increase in sequence
Hi all R helpers,
I'm trying to comeup with nice and elegant way of "detecting" consecutive
increases/decreases in the sequence of numbers. I'm trying with combination
of which() and diff() functions but unsuccesifuly.
For example:
sq <- c(1, 2, 3, 4, 4, 4, 5, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1);
I'd like to find way to calculate
a) maximum consecutive increase = 3 (from 1
2011 Oct 27
1
question R regarding consecutive numbers
Hi everyone
Do you know about any possibility in R to check for consecutive numbers in
vectors? That is, I do not only want to count the number of observations in
total (which can be done table(x)), but I also want to count for instance
how many times that vector contains a certain number consecutively.
For example in the following vector x the number "1" appears 7 times.
2011 Apr 08
5
Avoiding a loop
Friends.
I cannot simplify this much, and I think the loop is unavoidable. As a
recovering C programmer I want to avoid loops and in cases like this I
almost allways can by using an apply function. But I suspect in this case
there is nothing I can do.
It is a finance example where a price series is compared to a moving
average. If the price goes above the average, plus a bit, buy the
2008 Jun 02
4
NOT-SO-SIMPLE function!
I am trying to set up a function which processes my data according to the
following rules:
1. if (x[i]==0) NA
2. if (x[i]>0) log(x[i]/(number of consecutive zeros immediately preceding
it +1))
The data this will apply to include a variety of whole numbers not limited
to 1 & 0, a number of which may appear consecutively and not separated by
zeros. Below is an example with a detailed
2011 Jan 04
5
scoping/non-standard evaluation issue
Dear r-devel list members,
On a couple of occasions I've encountered the issue illustrated by the
following examples:
--------- snip -----------
> mod.1 <- lm(Employed ~ GNP.deflator + GNP + Unemployed +
+ Armed.Forces + Population + Year, data=longley)
> mod.2 <- update(mod.1, . ~ . - Year + Year)
> all.equal(mod.1, mod.2)
[1] TRUE
>
> f <-
2010 Jul 22
4
Drop firms in unbalanced panel if not more than 5 observations in consecutive years for all variables
Dear R-user,
a few weeks ago I consulted the list-serve with a similar question.
However, my task changed a little but sufficiently to get lost again. So
I would appreciate any help on the following issue.
I use the plm package and work with firm-level data in a panel. I would
like to eliminate all firms that do not fulfill the requirement of
having an observation in every variable used for at
2011 Oct 06
1
Concecutive zeros and ones
Dear all,
I have a data series (might be vector or matrix) which is composed only from zeros and ones like the following example
0 0 0 1 1 0 1 0 0 1 1 1 1 0 0 0
I want to be able to return back the length of concecutive zeros and the length of concecutive ones.
For that I want to have something like that returned:
zeros= [3 1 2 3];
ones=[2 1 4];
How I can do that simply in R?
I would like