Data manipulation
What zero values? And are they acutall zeros or are the NA's, that is, missing values? The code looks okay but without some sample data it is difficult to know exactly what you are doing. The easiest way to supply data is to use the dput() function. Example with your file named "testfile": dput(testfile) Then copy the output and paste into your email. For large data sets, you can just supply a representative sample. Usually, dput(head(testfile, 100)) will be sufficient. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Please supply some sample data. John Kane Kingston ON Canada
-----Original Message-----
From: ii54250 at msn.com
Sent: Fri, 15 Mar 2013 12:40:54 +0000
To: r-help at r-project.org
Subject: [R] Data manipulation
Hello all,
I would appreciate your thoughts on a seemingly simple problem. I have a
database, where each row represent a single record. I want to aggregate
this
database so I use the aggregate command :
D<-read.csv("C:\\Users\\test.csv")
attach(D)
by1<-factor(Class)
by2<-factor(X)
W<-aggregate(x=Count,by=list(by1,by2),FUN="sum")
The results I get following the form:
W
Group.1 Group.2 x 1 1 0.1 4 2 2 0.1 7 3 3 0.1 1 4 1 0.2 3 5 3 0.2 4 6 3 0.3 4 However, what I really want is an aggregation which includes the zero values, i.e.:
W
Group.1 Group.2 x
1 1 0.1 4
2 2 0.1 7
3 3 0.1 1
4 1 0.2 3
2 0.2 0
5 3 0.2 4
1 0.3 0
2 0.3 0
6 3 0.3 4
How can I achieve what I want?
Best regards,
Ioanna
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more!