[R] Converting dataframe to matrix

Noah Silverman noah at smartmediacorp.com
Fri Oct 16 10:55:03 CEST 2009


I think  you may be correct.

I've manage to get the data into a format that the function accepts.

The error appears to be because I have negative values in my data:

Error in apply(safeNormCDF(s), 1, prod) :
   dim(X) must have a positive length




On 10/16/09 1:51 AM, Philipp Pagel wrote:
> On Fri, Oct 16, 2009 at 01:33:14AM -0700, Noah Silverman wrote:
>    
>> Hi,
>>
>> I'm experimenting with a few learners that require a matrix as their
>> input.  (Currently svmpath, vbmp, etc.)
>>
>> I currently have a dataframe with 50 columns and 20,000 rows.
>>
>> I tried using:
>>
>> x<- as.matrix(my_data.frame)
>>
>> If I then as, "is.matrix(x)", I get TRUE.
>>
>> However everywhere I've tried to use the matrix returns errors.
>>      
> Without more information I can't even start to guess what is going
> wrong. Please give a short, reproducible example of what you did and
> what errors you encountered.
>
> as.matrix() should suffice for creating a matrix from a data.frame :
>
>    
>> foo<- data.frame(1:4, 4:1, sqrt(1:4), log(4:1))
>> foo
>>      
>    X1.4 X4.1 sqrt.1.4.  log.4.1.
>    1    1    4  1.000000 1.3862944
>    2    2    3  1.414214 1.0986123
>    3    3    2  1.732051 0.6931472
>    4    4    1  2.000000 0.0000000
>    
>> det(foo)
>>      
> Error in UseMethod("determinant") :
>    no applicable method for "determinant"
>    
>> det(as.matrix(foo))
>>      
> [1] -0.1092489
>
> So probably your problem is somewhere else.
>
> cu
> 	Philipp
>
>




More information about the R-help mailing list