

Hello
Please see the example below
> class(testX)
[1] "matrix"
> class(testX[1,])
[1] "numeric"
Why not matrix? What am I missing here? Is there a way to keep the same
class?
The reason for the question is that I want to implement a kstep ahead
prediction for my own routines and R wrecks does not seem to like [1,] as
shown below.
> predict(fit10,testX[1,])
Error in knnregTrain(train = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
dims of 'test' and 'train differ
> predict(fit10,testX[1:2,])
[1] 81.00 76.36
Many thanks
Ed
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Try this:
predict(fit10,testX[1,,drop = FALSE])
On Fri, Sep 2, 2011 at 5:05 PM, Eduardo M. A. M.Mendes
< [hidden email]> wrote:
> Hello
>
>
>
> Please see the example below
>
>
>
>> class(testX)
>
> [1] "matrix"
>
>> class(testX[1,])
>
> [1] "numeric"
>
>
>
> Why not matrix? What am I missing here? Is there a way to keep the same
> class?
>
>
>
> The reason for the question is that I want to implement a kstep ahead
> prediction for my own routines and R wrecks does not seem to like [1,] as
> shown below.
>
>
>
>> predict(fit10,testX[1,])
> Error in knnregTrain(train = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
> dims of 'test' and 'train differ
>> predict(fit10,testX[1:2,])
> [1] 81.00 76.36
>
>
>
> Many thanks
>
>
>
> Ed
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>

Henrique Dallazuanna
CuritibaParanáBrasil
25° 25' 40" S 49° 16' 22" O
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


In reply to this post by Eduardo M. A. M.Mendes
On Sep 2, 2011, at 3:05 PM, Eduardo M. A. M.Mendes wrote:
> Hello
>
>
>
> Please see the example below
>
>
>
>> class(testX)
>
> [1] "matrix"
>
>> class(testX[1,])
>
> [1] "numeric"
>
>
>
> Why not matrix? What am I missing here? Is there a way to keep the same
> class?
>
>
>
> The reason for the question is that I want to implement a kstep ahead
> prediction for my own routines and R wrecks does not seem to like [1,] as
> shown below.
>
>
>
>> predict(fit10,testX[1,])
> Error in knnregTrain(train = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
> dims of 'test' and 'train differ
>> predict(fit10,testX[1:2,])
> [1] 81.00 76.36
>
>
>
> Many thanks
>
>
>
> Ed
Ed,
See:
http://cran.rproject.org/doc/FAQ/RFAQ.html#Whydomymatriceslosedimensions_003fand then use:
predict(fit10, testX[1, , drop = FALSE])
HTH,
Marc Schwartz
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Many thanks to all for the reply.
I do apologize for bothering the list with a FAQ but I have to confess that,
although I read Faq in the past, I did not remember to do it again.
Cheers
Ed
Original Message
From: Marc Schwartz [mailto: [hidden email]]
Sent: Friday, September 02, 2011 5:16 PM
To: Eduardo M. A. M.Mendes
Cc: [hidden email]
Subject: Re: [R] How to keep the same class?
On Sep 2, 2011, at 3:05 PM, Eduardo M. A. M.Mendes wrote:
> Hello
>
>
>
> Please see the example below
>
>
>
>> class(testX)
>
> [1] "matrix"
>
>> class(testX[1,])
>
> [1] "numeric"
>
>
>
> Why not matrix? What am I missing here? Is there a way to keep the
same
> class?
>
>
>
> The reason for the question is that I want to implement a kstep ahead
> prediction for my own routines and R wrecks does not seem to like [1,]
> as shown below.
>
>
>
>> predict(fit10,testX[1,])
> Error in knnregTrain(train = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
> dims of 'test' and 'train differ
>> predict(fit10,testX[1:2,])
> [1] 81.00 76.36
>
>
>
> Many thanks
>
>
>
> Ed
Ed,
See:
http://cran.rproject.org/doc/FAQ/RFAQ.html#Whydomymatriceslosedimensions_003f
and then use:
predict(fit10, testX[1, , drop = FALSE])
HTH,
Marc Schwartz
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

