Skip to content
Back to formatted view

Raw Message

Message-ID: <941871A13165C2418EC144ACB212BDB001B63143@dshsmxoly1504g.dshs.wa.lcl>
Date: 2010-12-08T00:29:39Z
From: Nordlund, Dan (DSHS/RDA)
Subject: longer object length is not a multiple of shorter object length
In-Reply-To: <1291762900892-3077400.post@n4.nabble.com>

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of madr
> Sent: Tuesday, December 07, 2010 3:02 PM
> To: r-help at r-project.org
> Subject: [R] longer object length is not a multiple of shorter object
> length
> 
> 
> In datamatrix[, "y"] == datamatrix[, "y"][-1] :
>   longer object length is not a multiple of shorter object length
> 
> out = c(FALSE,datamatrix[,'y'] == datamatrix[,'y'][-1])
> 
> and I do not know why I get that error, the resulting out matrix is
> somehow
> one row larger than datamatrix...
> all I try to do is filter matrix by dropping rows where [,'y'][-1] ==
> [,'y'][+1]

If I understand what you want correctly, something like this may give you what you want

# create data fraome to work with
x <- 1:10
y <- c(2, 2, 4, 3, 5, 5, 4, 1, 2, 5)
df <- data.frame(x,y)

# out contains rows to drop out
out <- which(c(FALSE, df[-1,'y'] == df[-nrow(df), 'y']))
df[-out,]
 
# keep contains rows to keep
keep <- which(c(TRUE, df[-1,'y'] != df[-nrow(df), 'y']))
df[keep,]

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204