0

So, I have been doing my homework for Uni and got stuck with the problem of summarizing only specific columns with function

complete <- function(id= 1:332, summarise=F) {
  
  kek<- read.csv(paste("00", id,".csv", sep=""))
  if(summarise==T) {summary(kek)} else{return(kek)}
  

  }

The output I get is this:

Date              sulfate          nitrate             ID

Length:1461        Min.   : 0.613   Min.   :0.1180   Min.   :1    

Class :character   1st Qu.: 2.210   1st Qu.:0.2835   1st Qu.:1

Mode  :character   Median : 2.870   Median :0.4530   Median :1

                   Mean   : 3.881   Mean   :0.5499   Mean   :1

                   3rd Qu.: 4.730   3rd Qu.:0.6635   3rd Qu.:1

                   Max.   :19.100   Max.   :1.8300   Max.   :1

                   NA's   :1344     NA's   :1339

But I need it to look like this:

      Date              sulfate          nitrate             ID

   2003-01-01:    1   Min.   : 0.613   Min.   :0.1180   Min.   :1    

   2003-01-02:     1   1st Qu.: 2.210   1st Qu.:0.2835   1st Qu.:1

   2003-01-03:     1   Median : 2.870   Median :0.4530   Median :1

   2003-01-04:     1   Mean   : 3.881   Mean   :0.5499   Mean   :1

   2003-01-05:     1   3rd Qu.: 4.730   3rd Qu.:0.6635   3rd Qu.:1

   2003-01-06:     1   Max.   :19.100   Max.   :1.8300   Max.   :1

(Other)      : 1455    NA's   :1344     NA's   :1339

I have tried choosing only 2 to 4 columns, but it leaves out "Date"

smlnk
  • 1
  • Like the other user mentioned, please make your post [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by providing your data. – jrcalabrese Nov 21 '22 at 02:15

1 Answers1

0

Difficult to say without some example data, but you probably need to convert the data in the Date column of each data frame using as.Date() after it is imported.

https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/as.Date

Hope that helps.

MrSwaggins
  • 87
  • 8