-6

I have below CSV , learning R. Trying to write script to read CSV , aggregate Count by Survival (and or Class) and also plot percentages.

Something like Alive 711(sum of Count) 32.3% of total count. Please share how to do this in R/RStudio. Thanks!

Survival    Class   Count
Alive   First   203
Alive   Second  118
Alive   Third   178
Alive   Crew    212
Dead    First   122
Dead    Second  167
Dead    Third   528
Dead    Crew    673
thelatemail
  • 91,185
  • 12
  • 128
  • 188
Mohan Rayapuvari
  • 289
  • 1
  • 4
  • 18
  • Could you please share your data in some other way? – Hack-R Sep 12 '16 at 00:39
  • Have you taken a look at the `?aggregate` function? – thelatemail Sep 12 '16 at 01:00
  • You should try to look for some tutorial instead of asking questions like this here. If you break the task down to separate sub-tasks, I am sure you can find in first answers on google stuff like [read csv in R](http://stackoverflow.com/questions/13265153/how-do-i-import-a-csv-file-in-r), [aggreagate by column in R](http://stackoverflow.com/questions/6289538/aggregate-a-dataframe-on-a-given-column-and-display-another-column) and others. – JaKu Sep 12 '16 at 11:15
  • @Hack-R - I copied from excel and pasted it here. Please let me know if you are looking for granular dataset? I don't have granular , summarized table(above one) was provided in an assignment to learn R. – Mohan Rayapuvari Sep 15 '16 at 02:36
  • It's fine. I meant to format the data (like thelatemail did when he edited the question) and/or use `dput()`. Anyhow the answer is in the comment above, you should just use `aggregate()`. – Hack-R Sep 15 '16 at 02:58

1 Answers1

0

The first step (reading in the csv) is pretty simple:

data = read.table("filename.csv", sep = ",", quote = "", header=TRUE)

The 'sep' part makes it clear that the separator is a comma, and 'header' keeps those column headings separate from the rest of the data. Does that work for you? -Y