harrelfe / Hmisc

Harrell Miscellaneous
Other
205 stars 81 forks source link

list.tree() function shows integer for each column #89

Closed Uygar89 closed 6 years ago

Uygar89 commented 6 years ago

I have experimented with a few datasets and each time, when I invoked the list.tree function, it interpreted each column as integer, even though there were columns that didn't even contain a single integer.

harrelfe commented 6 years ago

Your message does not follow guidelines. Edit it to include a minimal working example with self-cointained data.

Uygar89 commented 6 years ago

list tree As you can see, almost all columns are either string or character. List.tree shows for each column Integer as column type... is that a bug, or did I do something wrong?

harrelfe commented 6 years ago

As requested previously include a minimal working example with self-contained generated data and code. Do not include screenshots.

Uygar89 commented 6 years ago
library(Hmisc) 
setwd("...")
df <- read.csv("filename.csv", sep = ";", header = TRUE)
list.tree(df)

Output: df = list 10 (590216 bytes)( data.frame ) . Beer.innerText = integer 2410= factor (2304 levels)( factor )= Get Together Maggie's Leap ... . Beer.url.href = integer 2410= factor (2410 levels)( factor )= http://craftcans.com/db.php?beer=2692 ... . Brewery.innerText = integer 2410= factor (551 levels)( factor )= NorthGate Brewing ... . Location.innerText = integer 2410= factor (401 levels)( factor )= Minneapolis, MN ... ....

couthcommander commented 6 years ago

@Uygar89 Your data set contains factor variables, which are internally stored as integer values -- thus list.tree is behaving as expected. The displayed characters strings are called factor levels. If you want actual character strings, you should add the argument stringsAsFactors=FALSE to read.csv.