[R] longer object length is not a multiple of shorter object length

2010-12-07 Thread madr

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]
-- 
View this message in context: 
http://r.789695.n4.nabble.com/longer-object-length-is-not-a-multiple-of-shorter-object-length-tp3077400p3077400.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] longer object length is not a multiple of shorter object length

2010-12-07 Thread Joshua Wiley
Hi,

On Tue, Dec 7, 2010 at 3:01 PM, madr madra...@interia.pl wrote:

 In datamatrix[, y] == datamatrix[, y][-1] :

suppose datamatrix has 10 rows, you select column y, and then for
the equality remove the first 'row' (technically element at this point
since you selected just column y).  So R is being asked to try to
compare rows 1 through 10 with rows 2 through 10 hence:

  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]

perhaps you want to compare rows 1 through 9 with 2 through 10?  That
is, see if there are any differences?  Following through wtih there
being 10 rows, you could remove the last one (replacing 10 with
however many you actually have):

datamatrix[, y][-10] == datamatrix[, y][-1]

or alternately you might look at the ?diff function:

diff(datamatrix[, y])

which will calculate differences based on the set lag (1 by default).
It seems like you might be interested in something like that.

Cheers,

Josh

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/longer-object-length-is-not-a-multiple-of-shorter-object-length-tp3077400p3077400.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] longer object length is not a multiple of shorter object length

2010-12-07 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of madr
 Sent: Tuesday, December 07, 2010 3:02 PM
 To: r-help@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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] longer object length is not a multiple of shorter object length

2010-11-03 Thread Stephen Liu
Hi folks,

I'm following An Introduction to R
http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics

to learn R.

Coming to;
2.2 Vector arithmetic

 v - 2*x + y + 1
Warning message:
In 2 * x + y :
  longer object length is not a multiple of shorter object length

What does it mean?  How to rectify it?  Please help.  TIA

B.R.
Stephen L



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] longer object length is not a multiple of shorter object length

2010-11-03 Thread David Winsemius


On Nov 3, 2010, at 11:00 AM, Stephen Liu wrote:


Hi folks,

I'm following An Introduction to R
http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics

to learn R.

Coming to;
2.2 Vector arithmetic


v - 2*x + y + 1

Warning message:
In 2 * x + y :
 longer object length is not a multiple of shorter object length

What does it mean?  How to rectify it?  Please help.  TIA


What does this return:

c(length(x), length(y))  # ?



David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] longer object length is not a multiple of shorter object length

2010-11-03 Thread Stephen Liu
- Original Message 

From: David Winsemius dwinsem...@comcast.net
To: Stephen Liu sati...@yahoo.com
Cc: r-help@r-project.org
Sent: Wed, November 3, 2010 11:03:18 PM
Subject: Re: [R] longer object length is not a multiple of shorter object length

- snip -

 v - 2*x + y + 1
 Warning message:
 In 2 * x + y :
  longer object length is not a multiple of shorter object length

 What does it mean?  How to rectify it?  Please help.  TIA

 What does this return:

 c(length(x), length(y))  # ?

c(length(x), length(y))
[1]  5 11


B.R.
Stephen L



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] longer object length is not a multiple of shorter object length

2010-11-03 Thread David Winsemius


On Nov 3, 2010, at 11:17 AM, Stephen Liu wrote:


- Original Message 

From: David Winsemius dwinsem...@comcast.net
To: Stephen Liu sati...@yahoo.com
Cc: r-help@r-project.org
Sent: Wed, November 3, 2010 11:03:18 PM
Subject: Re: [R] longer object length is not a multiple of shorter  
object length


- snip -


v - 2*x + y + 1
Warning message:
In 2 * x + y :
longer object length is not a multiple of shorter object length

What does it mean?  How to rectify it?


You were not supposed to rectify it. That example was designed to show  
you what happens in R when two vectors (actually three) are offered to  
the Arithmetic operators. Read the material that is above and below  
that expression again.




Please help.  TIA



What does this return:



c(length(x), length(y))  # ?


c(length(x), length(y))
[1]  5 11


B.R.
Stephen L




David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.