Read csv file - manipulate and convert to Data Table

I am reading a csv file in a Shiny app as follows:
40%20AM

I then want to summarize the contents of this read csv file and convert it to a Data Table as follows:

This seems not to work, how can i accomplish this. i have attached a sample .csv dataset
Affinity_Analysis.pdf (69.1 KB)
The expected output as a Data Table is as follows:
18%20AM

Looks like you're missing a %>% after group_by(Item).

Also, if you use read_csv() from the readr package, instead of read.csv(), you might get a tidier data import.

1 Like

Instead of read.csv use fread function from data.table package it will read it faster and import it as a data.table you won't have to convert it.

Df[,.(totalsales = sum(amount),
Customer = unique(customerid)),
Item]

So on.... And you will be able to solve all your problem at once.

Thank you very much for your input, i will try it out and advise accordingly

1 Like

Thank you very much for your input, most appreciated, will try and advise accordingly

1 Like

@Anantadinath I actually don't think he wants data.table, but data.frame, going by his use of dplyr.

data.table is a dataframe as well. It has 2 class structure. which inherits everything from dataframe.

True, but you wouldn't usually use dplyr with data.table, right, you would use data.table's own manipulation operators.

Its your own preference. He asked for a data table in question I have him a data table solution.

And you can use dplyr verbs with data.table as well. It will change the class from data.table to tibble and then you won't be able to use data.table syntax anymore but you can use dplyr all along. You can surely import a csv with fread without any side effects.

There is a new package called vroom if you want a faster operation on csv and fst if you want to store a large data set on computer. Definitely check those 2 as well.

He is talking about a Data Table in reference to the DT package to display tables on HTML pages or shiny apps (see tags for the topic), not a data.table.

1 Like

My bad I couldn't understand the question properly. :smiley::smiley::smiley:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.