Displaying 20 results from an estimated 10000 matches similar to: "as.list(subclassed function) -> cannot coerce type 'closure' to vector of type 'list'"
2010 Dec 01
1
attempted merge() returns: cannot coerce type 'closure' to vector of type 'any'
Hi Dimtris and esteemed useRs,
I don't understand why i get this error message when attempting to use
merge() -
> temp <- merge(x, y[,17, drop=FALSE], by=rownames, sort=FALSE)
Error in as.vector(x, mode) :
cannot coerce type 'closure' to vector of type 'any'
It should work because:
> all(rownames(x[order(rownames(x)),]) ==
+ rownames(y[order(rownames(y[,17,
2011 Apr 09
2
best practice(s) for retrieving a local variable from a closure
Greetings,
Say I have defined
mp <- function(a) function(x) x^a
f2 <- mp(2)
and I would like to retrieve the "a" which is local to f2. Two options
come to mind;
get("a", envir=environment(f2))
eval(substitute(a), environment(f2))
I'm curious if one of these is preferred over the other in terms of
efficiency, robustness, aesthetics, etc. Or perhaps
2012 Oct 16
2
cannot coerce class '"rle"' into a data.frame
why?
> rle
Run Length Encoding
lengths: int [1:1650061] 2 2 8 2 4 5 6 3 26 46 ...
values : chr [1:1650061] "4bbf9e94cbceb70c BG bg" "4fbbf2c67e0fb867 SK sk" ...
> as.data.frame(rle)
Error in as.data.frame.default(vertices.rle) :
cannot coerce class '"rle"' into a data.frame
it seems that
rle.df <-
2002 Oct 04
1
gnls from library nlme
Dear all,
I am trying to gain some experience with the function gnls from the nlme
package.
I tried to model the Theophyline data by trying to model the presumed
dependency of
the clearance on the body weight.
This is my function call of gnls:
gnls(conc~SSfol(Dose,Time,lKe,lKa,lCl),data=Theoph,
params=list(lKe~1,lKa~1,lCl~Wt),start=c(-2.4,0.46,-3.22,0.01))
That's been the result:
Error
2005 Jan 06
1
nls - convergence problem
Dear list,
I do have a problem with nls. I use the following data:
>test
time conc dose
0.50 5.40 1
0.75 11.10 1
1.00 8.40 1
1.25 13.80 1
1.50 15.50 1
1.75 18.00 1
2.00 17.00 1
2.50 13.90 1
3.00 11.20 1
3.50 9.90 1
4.00 4.70 1
5.00 5.00 1
6.00 1.90 1
7.00 1.90 1
9.00 1.10 1
12.00 0.95 1
14.00
2006 Feb 12
1
lme, nlsList, nlsList.selfStart
Dear listers,
I am trying to fit a model using nlsList() using alternately a SSfol()
selfstart function or its developped equivalent formulae.
This preliminary trial works well
mydata<-groupedData(Conc~Tps|Organ,data=mydata)
mymod1<-nls(Conc~SSfol(Dose,Tps,lKe,lKa,lCl),data=mydata)
as well as a developped form:
mymod2<-nls(Conc~Dose * exp(lKe+lKa-lCl) *
1997 May 21
2
R-alpha: factors ...
Perhaps someone can enlighten me here:
R> x <- factor(LETTERS[1:3])
R> x
[1] A B C
R> mode(x)
[1] "factor"
R> class(x)
[1] "factor"
R> mode(unclass(x))
[1] "factor"
S-PLUS has
> x <- factor(LETTERS[1:3])
> mode(x)
[1] "numeric"
> class(x)
[1] "factor"
> mode(unclass(x))
[1] "numeric"
???
2011 Mar 25
2
two minor bugs in rowsum()
(a) In R 2.12.2 rowsum can overflow if given an integer input:
> rowsum(c(2e9L, 2e9L), c("a", "a"))
[,1]
a -294967296
> 2^32 + .Last.value
[,1]
a 4e+09
Should it be changed to coerce its x argument to numeric
(double precision) so it always returns a numeric output?
(b) When rowsum is given an x containing both NaN and NA it
appears to use the last
2011 Jun 22
2
strange date problem - May 3, 1992 is NA
> is.na(strptime("5/2/1992", format="%m/%d/%Y"))
[1] FALSE
> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
[1] TRUE
Any idea what's going on with this? Running strptime against all dates
from around 1946, only 5/3/1992 was converted as "NA". Even stranger,
it still seems to have a value associated with it (even though is.na
thinks
2009 Sep 27
2
dimension-preserving matrix coersion
i've written a function to coerce a matrix (e.g. from numeric to
logical), but i'd like to know if someone has a more elegant method
for this:
> m <- matrix(c(0, 1, 1, 0), ncol = 2)
> m <- as.logical(m)
> m
[1] FALSE TRUE TRUE FALSE
i'd like 'm' to still be a matrix with the original dimensions. in my
function to do this, i coerce 'm' to a logical,
2013 Dec 13
2
how can i write the function into a file c:/mytest.R with cat function?
mytest<-function(x,f){
sum(x*f)/sum(f)
}
cat(mytest,file="c:/mytest.R")
Error in cat(list(...), file, sep, fill, labels, append) :
argument 1 (type 'closure') cannot be handled by 'cat'
how can i write the mytest function into a file c:/mytest.R with cat function?
[[alternative HTML version deleted]]
2013 May 20
3
as.vector with mode="list" and POSIXct
I was trying to convert a vector of POSIXct into a list of POSIXct, However, I had a problem that I wanted to share with you.
Works fine with, say, numeric:
> v = c(1, 2, 3)
> v
[1] 1 2 3
> str(v)
?num [1:3] 1 2 3
> l = as.vector(v, mode="list")
> l
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
> str(l)
List of 3
?$ : num 1
?$ : num 2
?$ : num 3
If you try it with POSIXct,
2018 Sep 05
4
True length - length(unclass(x)) - without having to call unclass()?
The bottomline here is that one can always call a base method,
inexpensively and without modifying the object, in, let's say,
*formal* OOP languages. In R, this is not possible in general. It
would be possible if there was always a foo.default, but primitives
use internal dispatch.
I was wondering whether it would be possible to provide a super(x, n)
function which simply causes the
2017 Jan 20
9
How to handle INT8 data
Hello r users,
I have to deal with int8 data with R. AFAIK R does only handle int4
with `as.integer` function [1]. I wonder:
1. what is the better approach to handle int8 ? `as.character` ?
`as.numeric` ?
2. is there any plan to handle int8 in the future ? As you might know,
int4 is to small to deal with earth population right now.
Thanks for you ideas,
int8 eg:
human_id
2009 Nov 11
2
partial cumsum
Hello,
I am searching for a function to calculate "partial" cumsums.
For example it should calculate the cumulative sums until a NA appears,
and restart the cumsum calculation after the NA.
this:
x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10)
should become this:
1 3 6 NA 5 11 18 26 35 45
any ideas?
thank you and best regards,
stefan
2009 Mar 10
4
puzzled by math on date-time objects
Hi,
I don't understand the following. When I create a small artificial set
of date information in class POSIXct, I can calculate the mean and the
median:
a = as.POSIXct(Sys.time())
a = a + 60*0:10; a
[1] "2009-03-10 11:30:16 EDT" "2009-03-10 11:31:16 EDT" "2009-03-10
11:32:16 EDT"
[4] "2009-03-10 11:33:16 EDT" "2009-03-10 11:34:16
2005 Apr 02
4
factor to numeric in data.frame
Dear All,
Assume I have a data.frame that contains also factors and I would like to
get another data.frame containing the factors as numeric vectors, to apply
functions like sapply(..., median) on them.
I read the warning concerning as.numeric or unclass, but in my case this
makes sense, because the factor levels are properly ordered.
I can do it, if I write for each single column
2001 Apr 09
1
Support for compartment models / matrix exponential method
I try to fit reaction kinetic data to a given hypothetical model
consisting of 3 ODEs. After some reading in Bates/Watts and the literature
cited there (e.g. Jennrich/Bright) I looked in R for functions that support
the use of the matrix exponential method. Until now I used for a similar
(but simpler) problem the nls package and fitted against the the parameterized
solution function. But this
2013 Feb 05
2
adjacency list to non-symmetric matrix
Dear R community,
is there an easy way to convert an adjacency list (or a data-frame) to a non-symmetric matrix?
The adjacency list has the following form:
person group
1 Sam a
2 Sam b
3 Sam c
4 Greg a
5 Tom b
6 Tom c
7 Tom d
8 Mary b
9 Mary d
I need the data in a matrix with persons as rows and groups as columns:
a b c d
Sam 1 1 1 0
Greg 1 0 0 0
Tom 0 1 1 1
Mary 0 1 0 1
I know that there
2008 Feb 16
3
Arithmetic bug? (found when use POSIXct) (PR#10776)
Full_Name: Bo Zhou
Version: 2.6.1 (2007-11-26)
OS: Windows XP
Submission from: (NULL) (207.237.54.242)
Hi,
I found an arithmetic problem when I'm doing something with POSIXct
The code to reproduce it is as follows (This is the recommended way of finding
out time zone difference on R News 2004-1 Page 32 URL
http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf)
a=Sys.time()