Displaying 20 results from an estimated 30000 matches similar to: "count zero or one in a list"
2009 Jul 07
2
rle
Hallo,
I have an other problem, I have this vector signData with an alternation of
1 and -1 that corrispond to the duration of two different percepts. I
extracted the durations like this:
signData<- scan("dataTR10.txt")
dur<-rle(signData)$length
Now I would like to extract only the positive duration, e.g.
signData <- c(1,1,1,1,-1,-1,-1,1,1,-1,-1)
posduration <- c(4,2)
I
2009 Feb 04
7
counting entries in vector
Hi all,
I've a vector with entries, which are all of the same type, e.g. string:
k <- c("bb", "bb", "bb", "aa", "cc", "cc")
and want to create a second vector containing the number of each entry
in k in the same order as in k, i.e.
c(3, 1, 2)
or:
k <- c(5,5,5,5,2,2,4)
=> c(4,2,1)
thanks
2007 Oct 01
4
how to plot a graph with different pch
I am trying to plot a graph but the points on the graph should be
different symbols and colors. It should represent what is in the legend.
I tried using the points command but this does not work. Is there
another command in R that would allow me to use different symbols and
colors for the points?
Thank you kindly.
data(mtcars)
plot(mtcars$wt,mtcars$mpg,xlab= "Weight(lbs/1000)",
2008 Sep 02
3
ftables package, zero rows
dear all,
i'm just about to do some straightforward contingency tables using ftables (and ctab() for percents).
the problem:
factor "a" are regions, factor "b" are subregions.
every region "a" consists of some subregions "b", but obviously not every subregion "b" is part of every region "a".
if i use the ftable() function, the
2008 Oct 21
1
Paddding an integer with zeros
Hello List,
Can anybody point me to a number-to-string formatting function?
I need to convert, say, 12 to 00012.
I tried format() but its too stubborn: it seems to only pad with spaces.
Thank you,
Your culpritNr1
--
View this message in context: http://www.nabble.com/Paddding-an-integer-with-zeros-tp20095300p20095300.html
Sent from the R help mailing list archive at Nabble.com.
2010 Jan 11
2
help needed to find zero areas in a vector
Dear Helpers:
I spend more than half a day to solve this problem in R:
Let x be a vector of a string of 0s and 1s, such as
x<-c(0,0,1,1,0,0,0,0,1,1,0,0,0,0). It can be a very long vector.
How to sub vectors of 0s? In the above example, I would like get the vectors (0,0), (0,0,0,0), (0,0,0,0).
I can use which(x==0) to get the index of the 0 elements, but I don't know how to get the
2009 Sep 14
4
local sequence function
hey,
I can not find a function for the following problem, hopefully you can
help me.
I have a vactor like this one
v = c(NA,NA,TRUE,TRUE,NA,TRUE,NA,TRUE,TRUE,TRUE)
and I would like to the TRUE values by the their "local sequence
number".
This means, the result should look thike this:
c(NA,NA,1,2,NA,1,NA,1,2,3)
Of course I could solve the problems using a loop, but this would be
2008 Jul 03
3
Re membering the last time an event occurred within a dataframe
All,
I am constructing a pharmacokinetic dataset and have hit a snag. The dataset
can be demonstrated in the following way:
myData <- data.frame(
evid = c(1, 0, 0, 0, 1, 0, 1, 1, 1, 0),
time = 1:10,
last.dose.time = c(1, 1, 1, 1, 5, 5, 7, 8, 9, 9)
)
The evid field is an indicator variable for whether the associated
observation is a dosing record (when it takes value 1) or an
2007 Oct 22
3
median value dataframe coming from multiple dataframes
Hi all,
I am not a skillful R programmer and has I am handling with large dataframes (about 30000 x 300) I am in need of an efficient function.
I have 4 dataframes with the same dimension. I need to generate other dataframe with the some dimension than the others where in each position it has the median value of the 4 values in the same position coming from the 4 dataframes.
Grateful by your
2009 Jun 12
3
replacing zeros by NAs
something like ...
> x<-c(1,2,3,0,5,6,0)
> is.na(x[x==0])<-T
> x
[1] 1 2 3 NA 5 6 NA
~~~~~~~~~~~~~~~~
Robert Kinley
~~~~~~~~~~~~~~~~
[[alternative HTML version deleted]]
2007 Nov 07
2
Trouble in creating a list
I want to create a list based on the information from a data.frame,
Model. So I tried the following:
MyList <- list(colnames(Model)[2] = levels(Model$(colnames(Model)[2])))
but it failed with an error:
Error: unexpected '=' in "list(colnames(Model)[2] ="
I have the following problems with this command line:
(1) I wanted to use colnames(Model)[2] as a tag for the list:
2009 Sep 08
5
sparse vectors
Hi
I deal with long vectors almost all of whose elements are zero.
Typically, the length will be ~5e7 with ~100 nonzero elements.
I want to deal with these objects using a sort of sparse
vector.
The problem is that I want to be able to 'add' two such
vectors.
Toy problem follows. Suppose I have two such objects, 'a' and 'b':
> a
$index
[1] 20 30 100000000
2008 Dec 18
1
inserting zero instances with zeroes in a matrix
Hi all,
Suppose I had the below example where a survey was carried out recording the number of each type of pet in each house
count<-c(2,1,2,1,2,3,4)
house<-c("house1","house1","house2","house3","house4","house4","house4")
2009 Jan 15
2
Linked count between matrix columns
Hello,
I create this array:
x <- cbind(c(1:4, rep(0,10)), c(rep(0,4), 1:2, rep(3,6), 4,5))
[,1] [,2]
[1,] 1 0
[2,] 2 0
[3,] 3 0
[4,] 4 0
[5,] 0 1
[6,] 0 2
[7,] 0 3
[8,] 0 3
[9,] 0 3
[10,] 0 3
[11,] 0 3
[12,] 0 3
[13,] 0 4
[14,] 0 5
I would like to do the following in vector syntax:
2011 Feb 15
2
Count factor if
Hi,
I have a data frame containing two columns:
x<-as.factor(c('a','a','a','a','a','b','b','b','c','d','d','d'))
y<-c(1,3,6,8,12,3,4,7,5,6,7,10)
X<-data.frame(x,y)
X
x y
1 a 1
2 a 3
3 a 6
4 a 8
5 a 12
6 b 3
7 b 4
8 b 7
9 c 5
10 d 6
11 d 7
12 d 10
I would like to
2010 Aug 21
4
basic hist() question
Hi list
I loaded the content of a file dureetasks.txt to variable a. This file
contains an interger per line.
when I print a vector, it displays correctly.
however, when I try to print the histogram, I get this error message
> a=read.table("dureetasks.txt")
> hist(a)
Error in hist.default(a) : 'x' must be numeric
Can you help please?
regards
--
PhD candidate in
2010 Oct 08
2
Count values in a dataframe with respect to groups
Dear all,
I am looking for a function to count values belonging to a class within a dataframe (and ignore NAs).
grp = c(1,1,1, 1,2, 2,2)
val = c(2,1,5,NA,3,NA,1)
dta = data.frame(grp=grp, val=val)
The result should look like:
grp count
1 3
2 2
At the moment, I am trying to find a function for FUN in aggregate, but with no success. Can anybody help me?
Thanks in advance.
Marcus
2008 Mar 24
6
vlookup in R
Hi,
Is there are function similar to excel vlookup in R. Please let me know.
Thanks,
Sachin
____________________________________________________________________________________
[[alternative HTML version deleted]]
2011 Jan 17
1
Replacing rows in a data frame
R-helpers,
Below is a simple example of some output that I am getting while trying to work with a data frame in R 2.12.1 for Mac.
-----
> testdat <- data.frame(matrix(ncol=10, nrow=10))
> colnames(testdat) <- c('a','b','c','d','e','f','g','h','i','j')
> testdat[seq(1,10,3),] <-
2007 Feb 23
4
How to plot two graphs on one single plot?
Hi,
I am trying to plot two distribution graph on one plot. But I dont know
how. I set them to the same x, y limit, even same x, y labels.
Code:
x1=rnorm(25, mean=0, sd=1)
y1=dnorm(x1, mean=0, sd=1)
x2=rnorm(25, mean=0, sd=1)
y2=dnorm(x2, mean=0, sd=1)
plot(x1, y1, type='p', xlim=range(x1,x2), ylim=range(y1, y2), xlab='x',
ylab='y')
plot(x2, y2, type='p',