inst/tests/test_as.data.frame_as.matrix.R

# Test of coercering a data.frame and a pdata.frame to matrix
# Currently (in at least rev. 195), there is a difference between the both.

library(plm)
data("Grunfeld", package = "plm")

pGrunfeld <- pdata.frame(Grunfeld)

matGrunfeld      <- as.matrix(Grunfeld)
matpGrunfeld     <- as.matrix(pGrunfeld)
mat_df_pGrunfeld <- as.matrix(as.data.frame(pGrunfeld))

class(matGrunfeld)
class(matpGrunfeld)
class(mat_df_pGrunfeld)

lapply(matGrunfeld,  function(x) class(x)) # all numeric
lapply(matpGrunfeld, function(x) class(x)) # all character

# Also all character in (at least) rev. 195, albeit pdata.frame was coerced to data.frame first
lapply(mat_df_pGrunfeld, function(x) class(x))

Try the plm package in your browser

Any scripts or data that you put into this service are public.

plm documentation built on April 9, 2023, 5:06 p.m.