Giorgio Garziano
2016-Apr-29 18:39 UTC
[R] selecting columns from a data frame or data table by type, ie, numeric, integer
Hi, I was able to replicate the solution as suggested by William in case of data.frame class, not in case of data.table class. In case of data.table, I had to do some minor changes as shown below. library(data.table) a <- 1:10 b <- c("a","b","c","d","e","f","g","h","i","j") c <- seq(1.1, .2, length = 10) # in case of data frame dt1 <- data.frame(a,b,c) dt1[vapply(dt1, FUN=is.numeric, FUN.VALUE=NA)] a c 1 1 1.1 2 2 1.0 3 3 0.9 4 4 0.8 5 5 0.7 6 6 0.6 7 7 0.5 8 8 0.4 9 9 0.3 10 10 0.2 # in case of data table dt1 <- data.table(a,b,c) dt1[, vapply(dt1, FUN=is.numeric, FUN.VALUE=NA), with=FALSE] a c 1 1 1.1 2 2 1.0 3 3 0.9 4 4 0.8 5 5 0.7 6 6 0.6 7 7 0.5 8 8 0.4 9 9 0.3 10 10 0.2 -- Best, GG [[alternative HTML version deleted]]
Possibly Parallel Threads
- selecting columns from a data frame or data table by type, ie, numeric, integer
- selecting columns from a data frame or data table by type, ie, numeric, integer
- selection columns by type, ie, numeric
- Finding Highest value in groups
- infelicity in `na.print = ""` for numeric columns of data frames/formatting numeric values