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

dot in dcast formula - anything goes #4371

Open
Henrik-P opened this issue Apr 10, 2020 · 0 comments
Open

dot in dcast formula - anything goes #4371

Henrik-P opened this issue Apr 10, 2020 · 0 comments
Labels
reshape dcast melt

Comments

@Henrik-P
Copy link

Henrik-P commented Apr 10, 2020

Disclaimer: this is basically me doing a mistake, but because it may raise a more general question -- if an argument value not described in the help text should result in an error -- I thought I just as well could share it.

My intention was to achieve the functionality of . (". represents no variable") in the dcast formula. But, I had forgot the correct syntax and just throwed in a 1 instead (I might have thought of the 'no variable' / intercept only in lm...).

The 1 in the formula gave the desired (dot-)result, but when I saw the . in the variable name I realized my mistake. Should it be possible to use argument values not described in the help text?

# some data
d <- data.table(x = rep(LETTERS[1:2], each = 4),
                y = rep(letters[1:2], each = 2),
                z = 1:8)

# correct dot code, which I had forgot
dcast(d, x + y ~ ., value.var = "z", fun.aggregate = sum)

# my erroneous code, with a 1 instead of a dot gives the same result
dcast(d, x + y ~ 1, value.var = "z", fun.aggregate = sum)
 #   x y  .
# 1: A a  3
# 2: A b  7
# 3: B a 11
# 4: B b 15

# just to try what may translate to a dot - anything..;)
dcast(d, x + y ~ "anything", value.var = "z", fun.aggregate = sum)
 #   x y  .
# 1: A a  3
# 2: A b  7
# 3: B a 11
# 4: B b 15
@jangorecki jangorecki added the reshape dcast melt label Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reshape dcast melt
Projects
None yet
Development

No branches or pull requests

2 participants