Re: [R] Creating a simple function

2019-09-21 Thread Duncan Murdoch
On 21/09/2019 9:05 a.m., Jeff Newmiller wrote: Your use of subset instead of select does not help, Whoops, sorry. Thanks for doing the real check. Duncan but a corrected example does indeed confirm your point. library(dplyr) str(data.frame(a=c(1,1,2,2), b=1:4) %>% select(b,a)) ## 'data.fr

Re: [R] Creating a simple function

2019-09-21 Thread Jeff Newmiller
Your use of subset instead of select does not help, but a corrected example does indeed confirm your point. library(dplyr) str(data.frame(a=c(1,1,2,2), b=1:4) %>% select(b,a)) ## 'data.frame':4 obs. of 2 variables: ## $ b: int 1 2 3 4 ## $ a: num 1 1 2 2 However the `[` issue is still

Re: [R] Creating a simple function

2019-09-21 Thread Duncan Murdoch
On 21/09/2019 7:38 a.m., Jeff Newmiller wrote: The dplyr::select function returns a special variety of data.frame called a tibble. I don't think that's always true. The docs say it returns "An object of the same class as .data.", and that's what I'm seeing: > str(data.frame(a=c(1,1,2,2), b=

Re: [R] Creating a simple function

2019-09-21 Thread Jeff Newmiller
The dplyr::select function returns a special variety of data.frame called a tibble. The tibble has certain features designed to make it behave consistently when indexing is used. Specifically, the `[` operator always returns a tibble regardless of how many columns are indicated by the column ind

Re: [R] Creating a simple function

2019-09-20 Thread Rui Barradas
Hello, Something like this? ctab <- function(data) { gmodels::CrossTable(as.matrix(data), prop.chisq = FALSE, prop.c = FALSE, prop.t = FALSE, format = "SPSS") } mtcars %>% select(cyl, gear) %>% ctab() Hope this helps, Rui Barradas Às 16:30 de 20/09/19, Zachary Lim escreveu: Hi, I'm t

Re: [R] Creating a simple function

2019-09-20 Thread Duncan Murdoch
On 20/09/2019 11:30 a.m., Zachary Lim wrote: Hi, I'm trying to create a simple function that takes a dataframe as its only argument. I've been using gmodels::CrossTable, but it requires a lot of arguments, e.g.: #this runs fine CrossTable(data$col1, data$col2, prop.chisq = FALSE, prop.c = FAL

[R] Creating a simple function

2019-09-20 Thread Zachary Lim
Hi, I'm trying to create a simple function that takes a dataframe as its only argument. I've been using gmodels::CrossTable, but it requires a lot of arguments, e.g.: #this runs fine CrossTable(data$col1, data$col2, prop.chisq = FALSE, prop.c = FALSE, prop.t = FALSE, format = "SPSS") Moreover