Dear experts, when trying to estimate an kernel density function with density(x) I get the following error message with imported data from either EXCEL or text files: Error in density(spr) : argument must be numeric. Other procedues such as truehist work. If I generate data within R density works fine. Does anybody have an idea? Yours -- Christoph Hanck Wissenschaftliche Hilfskraft Lehrstuhl f??r Empirische Wirtschaftsforschung, Prof. Dr. Wilfling http://www.wiwi.uni-muenster.de/~05/ WWU Muenster Tel.: +49-251-83 25043 eMail: 05chha at wiwi.uni-muenster.de
On Mon, 2004-07-05 at 08:34, Christoph Hanck wrote:> Dear experts, > > when trying to estimate an kernel density function with density(x) I get the following > error message with imported data from either EXCEL or text files: > > Error in density(spr) : argument must be numeric. > > Other procedues such as truehist work. If I generate data within R density works fine. > Does anybody have an idea?More than likely, your vector 'spr' was imported as a factor. This would possibly suggest that at least one value in 'spr' is not numeric. If the entire vector was numeric, this would not be a problem. It is also possible that you may have not specified the proper delimiting character during the import, which would compromise the parsed structure of the incoming data. Use: str(spr) and you will probably get Factor ... First, check to be sure that you have used the proper delimiting character during your import. See ?read.table for the family of related functions and the default argument values for 'sep', which is the delimiting character. You should also check your source data file, since it may be problematic. HTH, Marc Schwartz
Hello and thanks for your reply Hopefully, my answer arrives at the correct place like that (if not, I am sorry for bothering you, but please let me know...) To sum up my procedure (sp is exactly the same thing as spr, I had just tinkered with the names while trying sth. to solve this problem)> sp<-read.table("c:/ratsdata/sp3.txt", col.names="sp") > xd<-density(sp)Error in density(sp) : argument must be numeric The suggested remedies yield the following> str(sp)`data.frame': 195 obs. of 1 variable: $ sp: int 11 10 10 12 25 22 12 23 13 15 ...> xd<-density(as.numeric(sp))Error in as.double.default(sp) : (list) object cannot be coerced to double Hence, it does not seem to be a factor. Declaring it as numeric gives another error message, on which I haven't yet found any help in Google/the archive. Yours sincerely -- Christoph Hanck Wissenschaftliche Hilfskraft Lehrstuhl für Empirische Wirtschaftsforschung, Prof. Dr. Wilfling http://www.wiwi.uni-muenster.de/~05/ WWU Muenster Tel.: +49-251-83 25043 -- Christoph Hanck Wissenschaftliche Hilfskraft Lehrstuhl für Empirische Wirtschaftsforschung, Prof. Dr. Wilfling http://www.wiwi.uni-muenster.de/~05/ WWU Muenster Tel.: +49-251-83 25043 eMail: 05chha@wiwi.uni-muenster.de [[alternative HTML version deleted]]
Hello, thanks again.> Reading through "An Introduction to R" which is part of the default > documentation set would be helpful to you in better understanding data > types and dealing with data frame structures.I got the message! I admit that my systematic efforts into R may be considered wanting. -- Christoph Hanck Wissenschaftliche Hilfskraft Lehrstuhl f??r Empirische Wirtschaftsforschung, Prof. Dr. Wilfling http://www.wiwi.uni-muenster.de/~05/ WWU Muenster Tel.: +49-251-83 25043 eMail: 05chha at wiwi.uni-muenster.de
Hello! On Mon, 2004-07-05 at 15:34, Christoph Hanck wrote:> Dear experts, > > when trying to estimate an kernel density function with density(x) I get the following > error message with imported data from either EXCEL or text files: > > Error in density(spr) : argument must be numeric.Well, as R tells you: You should check, whether your data is of type "numeric". Depending on the way you import the data "spr" this may not be the case and you have to do> density(as.numeric(spr))which should work... Besides: please read the guidelines for posting (see http://www.R-project.org/posting-guide.html) giving some details on the procedure you use to read in the data may have helped to give you a precise answer! Regards, Winfried -- ----------------------------------------------------------------- Dr. Dipl.-Math. Winfried Theis, SFB 475, Projekt C5, Universit??t Dortmund, 44221 Dortmund e-mail: theis at statistik.uni-dortmund.de Tel.: +49/231/755-5903 FAX: +49/231/755-4387