1

When I call the dput() function on my df data frame I am presented with multiple classes.

df %>% dput()
#> ...
#> class = c("tbl_df", "tbl", "data.frame")
#> ...

How do I transform this data frame into a single class? I would get something like this I imagine:

df %>% dput()
#> ...
#> class = "data.frame"
#> ...

I'm having a separate issue and I suspect this (multiple classes in a date frame) may be a contributing factor.

Display name
  • 4,153
  • 5
  • 27
  • 75

1 Answers1

1

You can override the class like that:

class(df) <- "data.frame"

If you want to change the class in a pipe, from there, use df %>% "class<-"("foo")

Example:

data.table::data.table(x = rnorm(10)) %>% "class<-"("foo")
$`x`
 [1] -1.7728669 -0.3643645  0.4410907  0.3494225 -0.3214129  0.8595643  0.8794649  0.3891513
 [9] -2.2456579 -0.6045959

attr(,"row.names")
 [1]  1  2  3  4  5  6  7  8  9 10
attr(,"class")
[1] "foo"
linog
  • 5,786
  • 3
  • 14
  • 28
  • can you also add the way to write that into a pipe? is it something like `df %>% class("data.frame")` which doesn't quite seem to work. – Display name Apr 28 '20 at 13:57