tibble

R: Create empty tibble/data frame with column names coming from a vector

夙愿已清 提交于 2021-01-27 13:02:51
问题 I would like to create an empty data frame where the column names are coming from a character vector. for example, if this was my vector: vec <- letters[1:3] I would like create an empty data frame like the following: df <- tibble('a' = character(), 'b' = character(), 'c' = character()) however, I would like to iterate through the items in the vector to populate the dataframe names and not have to manually specify each one. In reality my vector has 40+ names. I've tried the following by they

R data.table: how to go from tibble to data.table to tibble back?

和自甴很熟 提交于 2021-01-22 05:24:10
问题 I use mainly tables in the tibble fromat from tidyverse , but for some steps, I use the data.table package. I want to see what is the best way of converting a data.table back to tibble ? I understand that data.table has some clever function setDT and setDF function, that convert from data.frame to data.table (and vice-versa) by reference, i.e. without making a copy. But what if I wanted to convert back to tibble ? Am I copying the data using as_tibble on the data.frame resulting from setDT()