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.

2
  • 1
    what does str(df) show? Commented Apr 28, 2020 at 13:51
  • @developer when I str(df) I get tibble [5,856 x 10] (S3: tbl_df/tbl/data.frame) followed by the column types which include "chr', "Date", and "logi". Commented Apr 28, 2020 at 14:14

1 Answer 1

2

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"
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.