Displaying 20 results from an estimated 10000 matches similar to: "Finding "runs" of TRUE in binary vector"
2003 Feb 02
3
Finding Missing Data Patterns
Dear R-Helpers,
I have a large data matrix, which contains missing data. The matrix
looks something like this:
1) X X X X X X NA NA NA
2) NA NA NA NA X X X X X
3) NA NA X X X X NA NA NA
4) X X X X X X X X X
5) X X NA NA X NA NA NA NA
and so on. Notice that the first row starts with complete data but ends
with missing. The second row starts with missing, but the rest is
2004 Sep 24
3
Error with repeat lines() in function
I have a function that does some plotting. I then add lines to the
plot. If executed one line at a time, there is not a problem. If I
execute the function, though, I get:
Error in ans[[1]] : subscript out of bounds
This always occurs after the second lines command, and doesn't happen
with all of my data points (some do not have errors). Any ideas?
Thanks,
Sean
2005 Jun 20
1
(no subject)
R friends,
I am using R 2.1.0 in a Win XP . I have a problem working with lists, probably I
do not understand how to use them.
Lets suppose that a set of patients visit a clinic once a year for 4 years
on each visit a test, say 'eib' is performed with results 0 or 1
The patients do not all visit the clinic the 4 times but they missed a lot
of visits.
The test is considered positive if it
2004 Nov 23
2
How to extract data?
I appreciate if anyone can help me,
I have a table as follow,
> rate
DATE VALUE
1 1997-01-10 5.30
2 1997-01-17 5.30
3 1997-01-24 5.28
4 1997-01-31 5.30
5 1997-02-07 5.29
6 1997-02-14 5.26
7 1997-02-21 5.24
8 1997-02-28 5.26
9 1997-03-07 5.30
10 1997-03-14 5.30
. ...... ...
. ...... ...
. ...... ...
I want to extract the DATE(s) on
2012 Feb 13
2
finding and describing missing data runs in a time series
Hi -
I am trying to find and describe missing data in a time series. For instance, in the library openair, there is a data frame called "mydata":
library(openair)
head(mydata)
date ws wd nox no2 o3 pm10 so2 co pm25
1 1998-01-01 00:00:00 0.60 280 285 39 1 29 4.7225 3.3725 NA
2 1998-01-01 01:00:00 2.16 230 NA NA NA 37 NA NA NA
3 1998-01-01 02:00:00
2003 Mar 28
1
overlapping pattern match (errata 2.0)
well! excuse me again but...
your.string <- "aaacdf"
nc1 <- nchar(your.string)-1
x <- unlist(strsplit(your.string, NULL)) ######## CORRECT
x2 <- c()
for (i in 1:nc1)
x2 <- c(x2, paste(x[i], x[i+1], sep="")) ######## ERRATA 2
cat("ocurrences of <aa> in <your.string>: ", length(grep("aa", x2)),
sep="", fill=TRUE)
Fran
2005 May 24
3
obtaining first and last record for rows with same identifier
I have a dataframe that contains fields such as patid, labdate, labvalue.
The same patid may show up in multiple rows because of lab measurements on
multiple days. Is there a simple way to obtain just the first and last
record for each patient, or do I need to write some code that performs that.
Thanks,
Steven
2005 Jun 24
1
r programming help II
Dear List,
Suppose we have a variable K.JUN defined as (with
1=wet, 0=dry):
K.JUN1984 = c(1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
K.JUN1985 = c(0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1,
1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1)
K.JUN1986 = c(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1)
2013 Jan 15
5
Code to fetch summary info from vector
Hi all,
Thanks in advance for any help.
I have a vector "b":
b=c(1,1,1,2,3,4,3,2,1,1,1,1,1,2,3,4,5,4,3.5,3,2,1,1,1)
Imagine b is river flow throughout time.
I would like some code that will generate the following information:
number of individual 'periods' where b>1 (= 2 in this case)
period 1 length = 5, max = 4
period 2 length = 8, max = 5
I can't figure anything
2003 Nov 14
2
bad performance of a function
Dear all
I need to find a length of true sequences in logical vector (see example 1). I found
a possible solution which is good but if I use it on a larger data set I experience a
substantial decrease in performance (example 2).
Example 1
set.seed(111)
x <- sample(c(T,F),50, replace=T)
system.time(cetnost <- as.numeric(table(which(x)-cumsum(x[which(x)]))))
[1] 0.00 0.00 0.03 NA NA
2004 Jun 29
2
binding rows from different matrices
Hello list,
I have 3 matrices with same dimension :
> veca=matrix(1:25,5,5)
> vecb=matrix(letters[1:25],5,5)
> vecc=matrix(LETTERS[1:25],5,5)
I would like to obtain a new matrix composed by alternating rows of these
different matrices (row 1 of mat 1, row 1 of mat 2, row 1 of mat 3, row 2
of mat 1.....)
I have found a solution to do it but it is not very pretty and I wonder if
I
2009 Jul 07
3
Numbering sequences of non-NAs in a vector
Greetings, I have a vector of the form:
[10,8,1,3,0,8,NA,NA,NA,NA,2,1,6,NA,NA,NA,0,5,1,9...] That is, a combination
of sequences of non-missing values and missing values, with each sequence
possibly of a different length.
I'd like to create another vector which will help me pick out the sequences
of non-missing values. For the example above, this would be:
2004 Jun 29
10
naive question
I have a 100Mb comma-separated file, and R takes several minutes to read it
(via read.table()). This is R 1.9.0 on a linux box with a couple gigabytes of
RAM. I am conjecturing that R is gc-ing, so maybe there is some command-line
arg I can give it to convince it that I have a lot of space, or?!
Thanks!
Igor
2007 Dec 20
1
creating a factor from dates by subject?
Dear R-help,
I have a data set consisting of measurements made on multiple
subjects. Measurement sessions are repeated for each subject on
multiple dates. Not all subjects have the same number of
sessions. To create a factor that represents the session, I do
the following:
data <- read.csv('test-data.csv') # data appended below
data$date <- as.Date(data$date,
2005 Jun 23
3
grep negation
hi,
using the example in the grep help:
txt <- c("arm","foot","lefroo", "bafoobar")
i <- grep("foo",txt); i
[1] 2 4
but how can i get the negation (1,3) when looking for 'foo'?
thanks,
m.
2011 Jun 07
1
count length of continues elements in a vector
I am performing a precipitation analysis. data is in the form of daily
precipitation amounts, e.g.
x<- c(4,5,3,0,0,0,2,4,6,4,0,0,0,2,2,0,3,4,1,0,...)
I would like to find the length of the "storm", length of storm would be
defined as the number of days with continues precipitation. in this case the
returned vector would be:
(3,4,2,3,...)
I would also like the amount of
2009 Nov 11
2
partial cumsum
Hello,
I am searching for a function to calculate "partial" cumsums.
For example it should calculate the cumulative sums until a NA appears,
and restart the cumsum calculation after the NA.
this:
x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10)
should become this:
1 3 6 NA 5 11 18 26 35 45
any ideas?
thank you and best regards,
stefan
2005 May 08
3
Light-weight data.frame class: was: how to add method to .Primitive function
Hi,
Encouraged by a tip from Simon Urbanek I tried to use the S3 machinery
to write a faster version of the data.frame class.
This quickly hits a snag: the "[.default"(x, i) for some reason cares
about the dimensionality of x.
In the end there is a full transcript of my R session. It includes the
motivation for writing the class and the problems I have encountered.
As a result I see
2012 Jun 19
2
how to use by function
hi all,
Assume I have data like
data<-rbind(c(1,2),c(1,3),c(2,1),c(3,2),c(3,4))
I want to get some matrix like
1,2,3
2,NA,NA
3,2,4
I'm using by
mat<-matrix(NA,3,3)
by(data,data[,1],mat[data[,1],]<-c(data[,2]))
but it doesn't work.
Any ideas?
thanks,
cowboy
2007 Feb 15
2
How to speed up or avoid the for-loops in this example?
Any advice, tips, clues or pointers to resources on how best to speed up
or, better still, avoid the loops in the following example code much
appreciated. My actual dataset has several tens of thousands of rows and
lots of columns, and these loops take a rather long time to run.
Everything else which I need to do is done using vectors and those parts
all run very quickly indeed. I spent quite a