Re: [Rcpp-devel] Doubt about best pratices

2022-04-30 Thread Dirk Eddelbuettel
This is not a well-posed Rcpp question as - matrix and data.frame are _fundamentally_ two different data types - matrix being _one_ and only one storage type, or class, stored as one vector with dimension attribute of size two for rows and cols; this makes it _efficient_ and you will see a m

Re: [Rcpp-devel] Doubt about best pratices

2022-04-30 Thread Jeff Newmiller
It is not possible to convert a data frame to a matrix without copying data. But normally algorithms that need a matrix become noticeably less efficient when applied to data frames. If this is your case, I would simply encourage the user to pass a matrix into your function in the first place. Th

Re: [Rcpp-devel] Doubt about best pratices

2022-04-30 Thread Roberto Spadim
Uhm Converting from one to other copy data? From dataframe to matrix at least? Em sáb., 30 de abr. de 2022 às 14:26, Jeff Newmiller < jdnew...@dcn.davis.ca.us> escreveu: > A data frame is designed to represent different types in different > columns. A matrix is designed so that all elements are t

Re: [Rcpp-devel] Doubt about best pratices

2022-04-30 Thread Jeff Newmiller
A data frame is designed to represent different types in different columns. A matrix is designed so that all elements are the same. It sounds like you need matrices for your algorithm. I would simply require that... or attempt to convert it immediately and stop if the result is not numeric. O

[Rcpp-devel] Doubt about best pratices

2022-04-30 Thread Roberto Spadim
Hi folks! What's the best pratices to accept a dataframe and numericmatrix in a function? Should I have two different methods to deal with NumericMatrix and DataFrame? Could I convert DataFrame to matrix? What's the impact of doing this, i.e. does the as.matrix copy dataframe data? Thanks in adv