Head and toes Head and toes - 1 year ago 100
R Question

Convert list with numeric and string variables to dataframe in R

I am wondering how I can convert a list with both numeric and string variables to a dataframe:

For example:



How can I convert x to a dataframe, such that when I call x I get:

aa bb cc
1 a Yes 1
2 b No 2
3 b No 4
4 b Yes 4
5 d Yes 3


Answer Source

You can do x<-as.data.frame(x).

Updated based on @Frank's good below, if you want to avoid converting characters to factors do

x<-as.data.frame(x, StringsAsFactors = FALSE).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download