0

Ok so I am imported the CSV file where I had all of my data.

The csv contained the following data. This was all in the excel spread sheet. It will be easy to understand.

     SocialIssue Frequency   RelFreq
1        Housing       245 0.2401961
2 Transportation       112 0.1098039
3    Health Care       153 0.1500000
4      Education        71 0.0696078
5           Food       133 0.1303922
6          Other       306 0.3000000

My "R" code. Here i just import the file and load the data. The data loads perfectly. But I don't know how to find the relative frequency from this. This is what i have so far.

data1 <- read.csv("C:/Users/jaina/Desktop/Question1CSV.csv", header = T)
table(data1$SocialIssue)/sum(data1$Frequency)

Now the above code turns out to be something like this:

 Education  Food    Health Care    Housing     Other Transportation 
 0.001     0.001    0.001          0.001       0.001 0.001

The relative frequency is obviously not right but that's all i can think of..Any help would be appreciated.

UPDATE i ALSO want to create the pie chart of Social Issue vs RelRreq, now when i try this:

data1 <- read.csv("C:/Users/jaina/Desktop/Question1CSV.csv", header = T)
data1$RelFreq = data1$Frequency / sum(data1$Frequency)
options(digits = 6)

pie(data1)

It gives me the following error.

Error in pie(data1) : 'x' values must be positive

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
user372204
  • 69
  • 2
  • 10
  • 2
    `table()` would be used to create the table you imported. Like if you had a bunch of rows that said `Housing` `table()` would count them up to 245 like you already have. Sounds like you just want something like `data1$RelFreq = data1$Frequency / sum(data1$Frequency)` – Gregor Thomas Jan 20 '17 at 23:55
  • Works..that is exactly what i wanted but is there any way i can keep the full answer and not the 2 digit answer. – user372204 Jan 20 '17 at 23:57
  • 1
    [How to control the number of digits printed in R](http://stackoverflow.com/q/2287616/903061) – Gregor Thomas Jan 20 '17 at 23:58

0 Answers0