hi all, i have a simple question. instead of defining my measurements in a static way like ... x <- c(-0.475, -1.553, -0.434, -1.019, 0.395) ... i'd like them to be read from a file ... x <- read.table("07a673ac0cb1f7f8fa293860566f633c/1/raw0.txt", header=FALSE) d1 <- density(x, kernel = "gaussian") with a formatting that looks like: 4.2840000000e-01 6.7583333333e-01 8.2920000000e-01 7.8566666667e-01 6.6336666667e-01 5.4080000000e-01 4.7283333333e-01 4.3770000000e-01 4.3743333333e-01 4.1026666667e-01 3.6283333333e-01 3.2770000000e-01 4.9096666667e-01 [...] R quits and says:> d1 <- density(x, kernel = "gaussian")Error in density.default(x, kernel = "gaussian") : argument 'x' must be numeric Calls: density -> density.default Execution halted is there any possibility to convert this / make this work? big thx for help
read.table() returns a data.frame by default. Try str(x). Options: d1 <- density(x[[1]], kernel = "gaussian") or x <- scan("07a673ac0cb1f7f8fa293860566f633c/1/raw0.txt") Hope this helps Allan. On 21/07/09 11:09, leo mueller wrote:> hi all, > > i have a simple question. instead of defining my measurements in a > static way like ... > > x<- c(-0.475, -1.553, -0.434, -1.019, 0.395) > > ... i'd like them to be read from a file ... > > x<- read.table("07a673ac0cb1f7f8fa293860566f633c/1/raw0.txt", header=FALSE) > d1<- density(x, kernel = "gaussian") > > with a formatting that looks like: > > 4.2840000000e-01 > 6.7583333333e-01 > 8.2920000000e-01 > 7.8566666667e-01 > 6.6336666667e-01 > 5.4080000000e-01 > 4.7283333333e-01 > 4.3770000000e-01 > 4.3743333333e-01 > 4.1026666667e-01 > 3.6283333333e-01 > 3.2770000000e-01 > 4.9096666667e-01 > [...] > > R quits and says: > > >> d1<- density(x, kernel = "gaussian") >> > Error in density.default(x, kernel = "gaussian") : > argument 'x' must be numeric > Calls: density -> density.default > Execution halted > > is there any possibility to convert this / make this work? > > big thx for help > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
On 21/07/2009 6:09 AM, leo mueller wrote:> hi all, > > i have a simple question. instead of defining my measurements in a > static way like ... > > x <- c(-0.475, -1.553, -0.434, -1.019, 0.395) > > ... i'd like them to be read from a file ... > > x <- read.table("07a673ac0cb1f7f8fa293860566f633c/1/raw0.txt", header=FALSE) > d1 <- density(x, kernel = "gaussian") > > with a formatting that looks like: > > 4.2840000000e-01 > 6.7583333333e-01 > 8.2920000000e-01 > 7.8566666667e-01 > 6.6336666667e-01 > 5.4080000000e-01 > 4.7283333333e-01 > 4.3770000000e-01 > 4.3743333333e-01 > 4.1026666667e-01 > 3.6283333333e-01 > 3.2770000000e-01 > 4.9096666667e-01 > [...] > > R quits and says: > >> d1 <- density(x, kernel = "gaussian") > Error in density.default(x, kernel = "gaussian") : > argument 'x' must be numeric > Calls: density -> density.default > Execution halted > > is there any possibility to convert this / make this work?read.table returns a dataframe, i.e. a list of vectors. density wants a vector. So you will probably get what you want using d1 <- density(x[[1]], kernel="gaussian") You can use names(x) to find the name of the 1st column for a nicer syntax; it is probably V1 (for "variable 1"), so you could do y <- x$V1 density(y, ...) Duncan Murdoch