Re: [R] how does a valid subscript can produce an subscript out of bounds error?

2014-07-05 Thread Witold E Wolski
Thank you. You example helped to FIX IT.

The problem is I guess somehow related to:
 class(msexp$pepinfo$transition_group_id)
[1] factor

and the whole R type conversion , riddle.

For subscripts my intuition is:  either require integer or do the
cast to the rowname type (character).
However, it seems that R somehow prefers to cast factors to integers...

it seems that %in% casts both vectors to the same type. But to which one?

Oh, I guess all this is neatly explained in the R standard ... but
websearching for it just returns:
standard deviation


a frustrated R user.

On 5 July 2014 02:18, Duncan Murdoch murdoch.dun...@gmail.com wrote:
 On 04/07/2014, 6:35 PM, Witold E Wolski wrote:
 how does a valid subscript (see first 2 lines) can produce an
 subscript out of bounds error (see line 4)?


 1 sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id)
 [1] 0
 2 sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt))
 [1] 0
 3 class(msexp$rt)
 [1] matrix
 4 msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,])
 Error in msexp$rt[msexp$pepinfo$transition_group_id, ] :
   subscript out of bounds



 x - matrix(1,1,1)
 rownames(x) - colnames(x) - 23
 23 %in% rownames(x)
 [1] TRUE
 x[23,]
 Error in x[23, ] : subscript out of bounds




-- 
Witold Eryk Wolski

__
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] how does a valid subscript can produce an subscript out of bounds error?

2014-07-05 Thread peter dalgaard

On 05 Jul 2014, at 16:19 , Witold E Wolski wewol...@gmail.com wrote:

 Thank you. You example helped to FIX IT.
 
 The problem is I guess somehow related to:
 class(msexp$pepinfo$transition_group_id)
 [1] factor
 
 and the whole R type conversion , riddle.
 
 For subscripts my intuition is:  either require integer or do the
 cast to the rowname type (character).
 However, it seems that R somehow prefers to cast factors to integers...
 
 it seems that %in% casts both vectors to the same type. But to which one?
 
 Oh, I guess all this is neatly explained in the R standard ... but
 websearching for it just returns:
 standard deviation
 

From help([)

 The index object ‘i’ can be numeric, logical, character or empty.
 Indexing by factors is allowed and is equivalent to indexing by
 the numeric codes (see ‘factor’) and not by the character values
 which are printed (for which use ‘[as.character(i)]’).

One reason for hanging on to this convention is that it allows you to do

plot(x, y, col=c(red,blue)[sex])

Another reason is that it is the broader definition: It works for indexing 
vectors that do not have names.

 
 a frustrated R user.
 
 On 5 July 2014 02:18, Duncan Murdoch murdoch.dun...@gmail.com wrote:
 On 04/07/2014, 6:35 PM, Witold E Wolski wrote:
 how does a valid subscript (see first 2 lines) can produce an
 subscript out of bounds error (see line 4)?
 
 
 1 sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id)
 [1] 0
 2 sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt))
 [1] 0
 3 class(msexp$rt)
 [1] matrix
 4 msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,])
 Error in msexp$rt[msexp$pepinfo$transition_group_id, ] :
  subscript out of bounds
 
 
 
 x - matrix(1,1,1)
 rownames(x) - colnames(x) - 23
 23 %in% rownames(x)
 [1] TRUE
 x[23,]
 Error in x[23, ] : subscript out of bounds
 
 
 
 
 -- 
 Witold Eryk Wolski
 
 __
 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] how does a valid subscript can produce an subscript out of bounds error?

2014-07-05 Thread Patrick Burns

I think you are somewhere between
Circle 8.2.6 of 'The R Inferno'

http://www.burns-stat.com/documents/books/the-r-inferno/

and the basics of subscripting

http://www.burns-stat.com/documents/tutorials/impatient-r/more-r-subscript/

Pat

On 05/07/2014 15:19, Witold E Wolski wrote:

Thank you. You example helped to FIX IT.

The problem is I guess somehow related to:

class(msexp$pepinfo$transition_group_id)

[1] factor

and the whole R type conversion , riddle.

For subscripts my intuition is:  either require integer or do the
cast to the rowname type (character).
However, it seems that R somehow prefers to cast factors to integers...

it seems that %in% casts both vectors to the same type. But to which one?

Oh, I guess all this is neatly explained in the R standard ... but
websearching for it just returns:
standard deviation


a frustrated R user.

On 5 July 2014 02:18, Duncan Murdoch murdoch.dun...@gmail.com wrote:

On 04/07/2014, 6:35 PM, Witold E Wolski wrote:

how does a valid subscript (see first 2 lines) can produce an
subscript out of bounds error (see line 4)?


1 sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id)
[1] 0
2 sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt))
[1] 0
3 class(msexp$rt)
[1] matrix
4 msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,])
Error in msexp$rt[msexp$pepinfo$transition_group_id, ] :
   subscript out of bounds







x - matrix(1,1,1)
rownames(x) - colnames(x) - 23
23 %in% rownames(x)

[1] TRUE

x[23,]

Error in x[23, ] : subscript out of bounds







--
Patrick Burns
pbu...@pburns.seanet.com
twitter: @burnsstat @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of:
 'Impatient R'
 'The R Inferno'
 'Tao Te Programming')

__
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] how does a valid subscript can produce an subscript out of bounds error?

2014-07-04 Thread Witold E Wolski
how does a valid subscript (see first 2 lines) can produce an
subscript out of bounds error (see line 4)?


1 sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id)
[1] 0
2 sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt))
[1] 0
3 class(msexp$rt)
[1] matrix
4 msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,])
Error in msexp$rt[msexp$pepinfo$transition_group_id, ] :
  subscript out of bounds


-- 
Witold Eryk Wolski

__
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] how does a valid subscript can produce an subscript out of bounds error?

2014-07-04 Thread Duncan Murdoch
On 04/07/2014, 6:35 PM, Witold E Wolski wrote:
 how does a valid subscript (see first 2 lines) can produce an
 subscript out of bounds error (see line 4)?
 
 
 1 sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id)
 [1] 0
 2 sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt))
 [1] 0
 3 class(msexp$rt)
 [1] matrix
 4 msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,])
 Error in msexp$rt[msexp$pepinfo$transition_group_id, ] :
   subscript out of bounds

 

How are we supposed to know, since you didn't show us

msexp$pepinfo$transition_group_id

or the thing it was indexing,

msexp$rt

?  Please post reproducible examples.

Duncan Murdoch

__
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] how does a valid subscript can produce an subscript out of bounds error?

2014-07-04 Thread Duncan Murdoch
On 04/07/2014, 6:35 PM, Witold E Wolski wrote:
 how does a valid subscript (see first 2 lines) can produce an
 subscript out of bounds error (see line 4)?
 
 
 1 sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id)
 [1] 0
 2 sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt))
 [1] 0
 3 class(msexp$rt)
 [1] matrix
 4 msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,])
 Error in msexp$rt[msexp$pepinfo$transition_group_id, ] :
   subscript out of bounds

 

 x - matrix(1,1,1)
 rownames(x) - colnames(x) - 23
 23 %in% rownames(x)
[1] TRUE
 x[23,]
Error in x[23, ] : subscript out of bounds

__
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.