1

I have a dataframe with 50 columns in that 25 columns are of type list. How can I convert them to final single dataframe with type as integer

I am doing it with

df_list=names(which(sapply(df,is.list))
df_list=df[df_list]
do.call("rbind",df_list)

But it does not do the conversion. How can I do it?

2 Answers 2

1

We can unlist the list columns by looping over the columns specified by 'df_list' and assign the output back

df[df_list] <- lapply(df[df_list], unlist)

data

df <- data.frame(col1 = 1:5, col2 = I(as.list(1:5)), col3 = I(as.list(6:10)))
df_list <- sapply(df, is.list)
Sign up to request clarification or add additional context in comments.

Comments

0

convert list to dataframe

df_list=df[df_list]
library(data.table)
rbindlist(df_list, idcol=TRUE)

Comments

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.