Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbind.fill type casting - bug or feature? (plyr_1.8.3) #263

Open
markheckmann opened this issue Aug 19, 2015 · 3 comments
Open

rbind.fill type casting - bug or feature? (plyr_1.8.3) #263

markheckmann opened this issue Aug 19, 2015 · 3 comments

Comments

@markheckmann
Copy link

I found that a dataframe character vector when row binded consistently was converted to numbers. It turns out that rbind and rbind.fill behave differently (seems to be unwanted behaviour):

library(plyr)
d1 <- data.frame(a=NA, b=NA)
d2 <- data.frame(a="A", b=1)

rbind(d1, d2)
       a  b
  1 <NA> NA
  2   A  1

and different results for rbind.fill

rbind.fill(d1, d2)
     a  b
  1 NA NA
  2  1  1

which is different from standard vector type casting which gives

c(NA, "A")
NA  "A"

The same occurs for zero column data frames:

d3 <- data.frame(a=integer(), b=integer())

rbind(d3, d2)
   a b
 1 A 1

rbind.fill(d3, d2)
  a b
1 1 1

c(integer(), "A")
[1] "A"

If the type is the same, the results are the same:

d3 <- data.frame(a=character(), b=integer())

rbind(d3, d2)
  a b
1 A 1

rbind.fill(d3, d2)
  a b
1 A 1
@hadley
Copy link
Owner

hadley commented Aug 19, 2015

d2 doesn't contain a character vector...

@markheckmann
Copy link
Author

uups, of course, my mistake. TIL: do not work late night. okay, so rbind.fill handling is more in line with standard type R casting than rbind as c(NA, factor("A")) gives > NA 1. Thanks!

@hadley
Copy link
Owner

hadley commented Aug 21, 2015

I only recognise it because it's happen to me so so so so many times

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants