excel - Reading horizontal (row-based) data from xlsx files into R data frames -


this "let's try way" post related this one:

is possible define/modify reading function

  • can handle fact data stored in xlsx file row-based (i.e. each row represents variable)

  • and transforms accordingly can stored in column-based data.frame (i.e. used row in xlsx becomes column)

  • while capturing underlying class/data type of row-based variables?

regarding csv files start turning readlines, unfortunately xlsx still black box me.

here's little xlsx file features examples both data orientations: https://github.com/rappster/stackoverflow/blob/master/excel/row-and-column-based-data.xlsx

what modifying read.xlsx function xlsx package:

library(xlsx) read.transposed.xlsx <- function(file,sheetindex) {         df <- read.xlsx(file, sheetindex = sheetindex , header = false)         dft <- as.data.frame(t(df[-1]), stringsasfactors = false)          names(dft) <- df[,1]          dft <- as.data.frame(lapply(dft,type.convert))         return(dft)             }  # let's test read.transposed.xlsx("row-and-column-based-data.xlsx", sheetindex = 2) #    variable var_1 var_2 var_3 #1 2016-01-01     1      true #2 2016-01-02     2     b false #3 2016-01-03     3     c  true 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

post - imageshack API cURL -

dataset - MPAndroidchart returning no chart Data available -