[R] Odp: Missing index in vector assignment

Petr PIKAL petr.pikal at precheza.cz
Wed Mar 17 11:25:47 CET 2010


Hi

r-help-bounces at r-project.org napsal dne 17.03.2010 00:03:21:

> Dear r-helpers,
> 
> I am getting a mismatch error between two variables:
> 
>   svp <- ksvm(x, y, type="nu-svc")
>   Error in .local(x, ...) : x and y don't match.
> 
> and I suspect that it might be due to missing index in the y variable 
which

Why suspect? It is probably better to read the docs. Try

?ksvm

and see how x or y shall be defined. 

Besides why do you expect everybody knows what ksvm is

I get

> ??ksvm
No help files found with alias or concept or title matching ‘ksvm’
using regular expression matching.

therefore I the function is not a part of my installed packages.

> I defined as:
> 
>   y <- (LVvar[,1])
> 
> I tried various methods to make the y assignment in the same format as 
x,
> which is a dataframe
>   x <- (LVvar[,-1])
> 
> and looks like
>  x
>    rCoordCap rKnowGrow rGoalcom rSupport  rOpcomm rT2Cadap
> 1   4.979167  4.500000 5.812500 6.145833 5.979167 5.031250
> ...
> 
> but I still get y without the indexes as a vector:
>  y
>  [1] -1.00000000 -6.91193182 -1.00000000  0.74431818 -6.91193182
> 
> 
> Why are the results different for x and y, even though the assignment is 
the
> same
> except I exclude the columns for y?

LVvar is probably data frame. So x is data frame too but y lost dimension 
so it is a vector.

Help page for subsetting is a bit complicated as it has to cover various 
object types.

?"["

Basically if you want to keep dimensions = you has to use drop=FALSE 
option in subsetting. Default is FALSE so whenever result is only one 
column of data frame it is coerced to vector.

drop: logical.  If ‘TRUE’ the result is coerced to the lowest
          possible dimension.  The default is to drop if only one
          column is left, but *not* to drop if only one row is left.

Regards
Petr

> 
> Cheers,
> Chaehan
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list