R76.R

# making table data sets
library(dplyr)
library(tidyr)
library(MorpheusData)

#############benchmark 90
dat <- read.table(text=
"  x y value.1 value.2
    red a       1      13
    red b       2      14
    red c       3      15
    red d       4      16
   blue a       5      17
   blue b       6      18
   blue c       7      19
  blue d       8      20", header=T)

write.csv(dat, "data-raw/r76_input1.csv", row.names=FALSE)

df_out = dat %>%
      gather(Var, val, value.1, value.2) %>% 
      unite(Var1,Var, y) %>% 
      spread(Var1, val)

write.csv(df_out, "data-raw/r76_output1.csv", row.names=FALSE)

r76_output1 <- read.csv("data-raw/r76_output1.csv", check.names = FALSE)
fctr.cols <- sapply(r76_output1, is.factor)
int.cols <- sapply(r76_output1, is.integer)

r76_output1[, fctr.cols] <- sapply(r76_output1[, fctr.cols], as.character)
r76_output1[, int.cols] <- sapply(r76_output1[, int.cols], as.numeric)
save(r76_output1, file = "data/r76_output1.rdata")

r76_input1 <- read.csv("data-raw/r76_input1.csv", check.names = FALSE)
fctr.cols <- sapply(r76_input1, is.factor)
int.cols <- sapply(r76_input1, is.integer)

r76_input1[, fctr.cols] <- sapply(r76_input1[, fctr.cols], as.character)
r76_input1[, int.cols] <- sapply(r76_input1[, int.cols], as.numeric)
save(r76_input1, file = "data/r76_input1.rdata")
fredfeng/MorpheusData documentation built on May 16, 2019, 2:42 p.m.