Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
656 B
3
Indexable
Never
prices        = c()
year_months   = c()
prices        = 0

map <- function(.,lines) {
  
  data <- read.csv(textConnection(lines), header = TRUE, col.names = c("TIPO_DOCUMENTO", "DATA", "IMPORTO"))
  
  for (line in lines){
    if(grepl("FATTURA", line)){
      splitted_r  = unlist(strsplit(line, ","))
      price       = as.numeric(splitted_r[3])
      prices      = append(prices, price)
      year_month  = as.character(str_sub(ymd(splitted_r[2]),1,7))
      year_months = append.(year_months, year_month)
    }
  }
  return(keyval(year_months, prices))
}

#formattazione .csv
TIPO_DOCUMENTO,DATA,IMPORTO
FATTURA,20160104,139.8
FATTURA,20160104,160.92