On 12-10-23 5:39 AM, Rui Barradas wrote:
Hello,
Try the following.
y=c(2,3,5,2,4,6,8,3,6,2,5)
first <- function(x) min(which(x))
prefix <- function(x, v) x[seq_len(v)]
suffix <- function(x, v) x[-seq_len(v)]
first(y > 4)
prefix(y, first(y > 4))
suffix(y, first(y > 4))
Be careful with this:
Hello,
Try the following.
y=c(2,3,5,2,4,6,8,3,6,2,5)
first <- function(x) min(which(x))
prefix <- function(x, v) x[seq_len(v)]
suffix <- function(x, v) x[-seq_len(v)]
first(y > 4)
prefix(y, first(y > 4))
suffix(y, first(y > 4))
Hope this helps,
Rui Barradas
Em 23-10-2012 10:21, Al Ehan escr
Hi,
Is it what you're looking for?
which(y>4) ##all indexes for y>4
[1] 3 6 7 9 11
which(y>4)[1] ##the first index
[1] 3
HTH,
Ivan
--
Ivan CALANDRA
Université de Bourgogne
UMR CNRS/uB 6282 Biogéosciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calan...@u-bourgogn
Hi,
I got a small problem on how to define the vector index without manually
inspect the vector.
example:
y=c(2,3,5,2,4,6,8,3,6,2,5) #I have ten set of this kind of vectors (with
different values but same length) that I would also like to run the routine
below
#say;
v=the first index in y where
Here is one other solution. This one uses sqldf and is the SQL
analogue of Henrique's solution. It merges df with a copy of itself
restricted to those rows with groupLeader equal to 1 displaying the
indicated columns.
library(sqldf)
sqldf("select b.personId, b.groupId, b.groupLeader, b.someAttri
Try this. The function f takes a vector of indices and returns the
attribute for the unique groupLeader row among them. We use ave to
apply to each set of indices having a common groupId.
f <- function(ix) with(df[ix,], someAttribute[groupLeader == 1])
transform(df, leaderAttribute = ave(1:nrow(d
Try this:
merge(df, subset(df, groupLeader == 1, select = c(groupId,
someAttribute)), by = "groupId")[,-5]
On Tue, Dec 22, 2009 at 8:42 AM, Bertolt Meyer wrote:
> Dear List,
>
> I work with multilevel data from psychological group experiments and have
> frequently encountered a situation for wh
one approach is:
Dat <- read.table(textConnection("
personId groupId groupLeader someAttribute leaderAttribute
11 17 0 0.14583 NA
22 17 1 0.21875 NA
33 17 0 0.089743590 NA
4
Dear List,
I work with multilevel data from psychological group experiments and
have frequently encountered a situation for which I haven't found an
elegant solution: I need to assign the value of a specific group
member to all members of the group. For example, I have a group leader
(ide
9 matches
Mail list logo