Displaying 20 results from an estimated 1139 matches for "ans".
Did you mean:
and
2010 Jul 29
1
Using 'dimname names' in aperm() and apply()
...hink that the "dimname names" of tables and arrays could make
aperm() and apply() (and probably some other functions) easier to use.
(dimname names are, for example, created by table() )
The use would be something like:
--
x <-table( from=sample(3,100,rep=T), to=sample(5,100,rep=T))
trans <- x / apply(x,"from",sum)
y <- aperm( trans, c("from","to") )
z <- aperm(y, c("to","from") )
res <-apply( y, "to", sum)
--
This makes the array much easier to handle than having to keep track
which dimension currently means...
1999 Nov 11
2
dimname'less array breaks apply (PR#318)
<<insert bug report here>>
> apply(array(1:20,c(2,2,5)),2:3,function(x) x)
Error: length of dimnames must match that of dims
>
Changing:
dimnames = if (is.null(dn.ans)) list(ans.names, NULL) else c(list(ans.names), dn.ans)
To:
dimnames = if (length(dn)==0) NULL else
if (is.null(dn.ans)) list(ans.names, NULL) else c(list(ans.names), dn.ans)
seems to fix this.
Chuck Berry
--please do not edit the information below--
Version:
platform = sparc-sun-solari...
2005 Aug 22
2
problem building dendrograms to use with heatmap()
...ed code below which reproduces the problem and below that the output
from a run of that code on my computer.
Any help would be greatly appreciated. Thanks in advance.
-Ben
########################### begin code ###################################
version
dendro.leaf <- function(label) {
ans <- list()
attr(ans, 'members') <- 1
attr(ans, 'height') <- 0
attr(ans, 'leaf') <- T
attr(ans, 'midpoint') <- 0
attr(ans, 'label') <- label
attr(ans, 'class') <- 'dendrogram'
ans
}
dendro.merge <- function...
2011 Sep 09
4
Very simple question about list components
I have a list 'ans' from the following code:
tt <- rnorm(50)
rr <- rnorm(50)
ans <- lm(rr~tt)
ans[1] is "$coefficients", ans[2] is "$residuals", ans[3] is
"$effects", ... and so on up to ans[12]. Is there an easy way to
display just these names and not the data they contai...
2020 Aug 14
0
Bug in stats:::`[.formula`: (~ NULL)[2] gives Error ... missing value where TRUE/FALSE needed
Hi, it looks like:
> stats:::`[.formula`
function (x, i)
{
ans <- NextMethod("[")
if (length(ans) == 0L || as.character(ans[[1L]])[1L] == "~") {
class(ans) <- "formula"
environment(ans) <- environment(x)
}
ans
}
<bytecode: 0x556688d87cc0>
<environment: namespace:stats>
doesn't...
2007 May 23
1
Readline - wait for user input
...#39;ve seen various posts on this question, but still can't get the code
right.
If I run the following code one line at a time, it works fine. If I run
it together as a block, however, it doesn't wait for the input and gives
an error.
There must be a way to have are pause/wait for an answer, but I can't
seem to find it. Thanks! J
Code:
choosefunction <- function(){readline("1. linear, 2. linear with lag, 3.
nonlinear ")}
ans <- as.integer(choosefunction())
if (ans==1){K2=x1}
if (ans==2){K2=x2 }
if (ans==3){K2=x3 }
ans
Error text:
> ans <- as.intege...
2004 Jan 12
1
question about how summary.lm works
...== 0) {
r <- z$residuals
n <- length(r)
w <- z$weights
if (is.null(w)) {
rss <- sum(r^2)
}
else {
rss <- sum(w * r^2)
r <- sqrt(w) * r
}
resvar <- rss/(n - p)
ans <- z[c("call", "terms")]
class(ans) <- "summary.lm"
ans$aliased <- is.na(coef(object))
ans$residuals <- r
ans$df <- c(0, n, length(ans$aliased))
ans$coefficients <- matrix(NA, 0, 4)
dimnames(ans$co...
2011 Oct 05
4
SPlus to R
...are the first few lines of the S-Plus file:
sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8,
tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5)
{
### for method 1
if (method==1) {
ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01)
return(ne=ne1)
}
My translation looks like this:
sshc<-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8,
tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5)
{
### for method 1
if (method==1) {
ne1<-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01)
return(ne=ne1)
}
The program...
2011 Mar 10
3
lattice xscale.components: different ticks on top/bottom axis
...a plot where horizontal axes
limits are c(0,10), top axis has ticks at odd integers, and bottom axis
has ticks at even integers.
library(lattice)
df <- data.frame(x=1:10,y=1:10)
xscale.components.A <- function(...,user.value=NULL) {
# get default axes definition list; print user.value
ans <- xscale.components.default(...)
print(user.value)
# start with the same definition of bottom and top axes
ans$top <- ans$bottom
# - bottom labels
ans$bottom$labels$at <- seq(0,10,by=2)
ans$bottom$labels$labels <- paste("B",seq(0,10,by=2),sep="-")...
2004 Feb 11
1
.Call setAttrib(ans,R_DimSymbol,dim); Crashes.
Hi!
I want to return a matrix.
The code does the R interfacing.
This version does it fine.
SEXP ans,dim;
PROTECT(ans = NEW_NUMERIC(count*2));
memcpy(NUMERIC_POINTER(ans),result,count*sizeof(double));
memcpy(&(NUMERIC_POINTER(ans)[count]),occur,count*sizeof(double));
/** PROTECT(dim=NEW_INTEGER(2));
INTEGER_POINTER(dim)[0]=2;
INTEGER_POINTER(dim)[1]=count;
setAttrib(ans,R_Dim...
2005 Jun 01
2
A suggestion to improve ifelse behaviour with vector yes/noarguments
...t;
> Maybe this is something that should have been changed in R 2.0.0; we
> squandered that change from 1.x.x to 2.x.x.
>
> Duncan Murdoch
Hello,
I'm happy with the modified ifelse:
ifelse.o <- function (test, yes, no)
{
storage.mode(test) <- "logical"
ans <- test
nas <- is.na(test)
if (any(test[!nas]))
ans[test & !nas] <- rep(yes, length.out = length(ans))[test &
!nas]
if (any(!test[!nas]))
### Changed
ans[!test & !nas] <- rep(no, length.out = length(ans[!test & !nas]))
ans...
2007 Dec 11
0
holidayNYSE missing some
...nikkoam.com
> <mailto:A4678959B3D65D449266DE8D3825E0821F7F47@nycmsg501.nikkoam.com>>
> > Content-Type: text/plain; charset="us-ascii"
> >
> > This is deliberate behavior. If you check the code, the third-to-last
> > line is as follows:
> > ans = ans[!(as.POSIXlt(ans@Data)$wday == 0 |
> > as.POSIXlt(ans@Data)$wday== 6)]
> >
> >
> > You could make an alternate version of holidayNYSE that omits this line,
> > if you like.
> >
> > -CN
> >
> > Charles Naylor
> > Assistant Vice Presid...
2004 May 10
7
strange behavior of names<-
Dear R-help,
I've encounter what seems to me a strange problem with "names<-". Suppose I
define the function:
fun <- function(x, f) {
m <- tapply(x, f, mean)
ans <- x - m[match(f, unique(f))]
names(ans) <- names(x)
ans
}
which subtract out the means of `x' grouped by `f' (which is the same as,
e.g., resid(lm(x~f)) if `f' is a factor). If `x' does not have names, then
I'd expect the output of the function not to have names...
2004 Aug 30
0
small bug in apply() ??? (PR#7205)
...ed
vector of length >=2. I propose the source of the bug and the fix below,
but let me stick to the facts first.
Here is an example:
>a<-array(1:24, dim=2:4)
> func1<-function(x)c(a=mean(x),b=max(x))
> func2<-function(x)c(mean(x),max(x))
> apply(a,1:2,func1)
Error in array(ans, c(len.a%/%d2, d.ans), if (is.null(dn.ans)) { :
length of dimnames [2] must match that of dims [3]
> apply(a,1:2,func2)
, , 1
[,1] [,2]
[1,] 10 11
[2,] 19 20
, , 2
[,1] [,2]
[1,] 12 13
[2,] 21 22
, , 3
[,1] [,2]
[1,] 14 15
[2,] 23 24
*********...
2008 Apr 15
1
by inconsistently strips class - with fix
summary:
The function 'by' inconsistently strips class from the data to which
it is applied.
quick reason:
tapply strips class when simplify is set to TRUE (the default) due to
the class stripping behaviour of unlist.
quick answer:
This can be fixed by invoking tapply with simplify=FALSE, or changing
tapply to use do.call(c instead of unlist
executable example:
mytimes=data.frame(date = 1:3 + Sys.time(), set = c(1,1,2))
by(mytimes$date, mytimes$set, function(x)x)
INDICES: 1
[1] "2008-04-15 11:41:38 BST" &...
2007 Jun 18
1
Readline
...; >> If I run the following code one line at a time, it works fine.
If I run
>> >> it together as a block, however, it doesn't wait for the input
and gives
>> >> an error.
>> >>
>> >> There must be a way to have are pause/wait for an answer, but I
can't
>> >> seem to find it. Thanks! J
>> >>
>> >> Code:
>> >>
>> >> choosefunction <- function(){readline("1. linear, 2. linear with
lag, 3.
>> >> nonlinear ")}
>> >> ans <-...
2008 Jul 07
2
A shorter version of ".Last.value"?
Hi,
There is an object, ".Last.value" to which the result of the most recent
evaluation is assigned. This is similar to "ans" in Matlab. In Matlab
"ans" can be very useful and time-saving, but typing the larger R
version is somewhat clunky and takes away from the usefulness.
Is it possible to reassign '.Last.value' to something simpler, like 'ans' ?
I'm aware of this thread:
http:...
2014 Jun 24
2
using C code to create data frame but always return as list
there is my code, expect return value is a data frame but R say it is list:
SEXP Julia_R_MD_NA_DataFrame(jl_value_t* Var)
{
SEXP ans,names,rownames;
char evalcmd[4096];
int i;
const char* dfname="DataFrameName0tmp";
jl_set_global(jl_main_module, jl_symbol(dfname), (jl_value_t*)Var);
//Get Frame cols
sprintf(evalcmd,"size(%s,2)",dfname);
jl_value_t* cols=jl_eval_string(evalcmd);
int collen=jl_unbox_lo...
2004 Aug 05
8
or of a logical vector
Is there some fast (built-in?) way to get the OR of all the elements in a
logical vector?
In other words, is there some fast (built-in) version of the function vor
below?
Thanks.
-Ben
vor <- function(v) {
ans <- v[1]
if (length(v) > 1)
for (i in 2:length(v))
ans <- ans | v[i]
ans
}
1998 Apr 02
1
attributes now inherited
...o USA
(where the sun will soon set into the mountains)
**************************************************************************
*** arithmetic.c Mon Nov 10 19:35:01 1997
--- /net/aster/R/src/main/arithmetic.c Wed Apr 1 16:33:27 1998
***************
*** 428,433 ****
--- 428,443 ----
else
ans = allocVector(INTSXP, n);
+ /* copy attributes from longest argument */
+ if (n1 > n2)
+ copyMostAttrib(s1, ans);
+ else if (n1 == n2) {
+ copyMostAttrib(s2, ans);
+ copyMostAttrib(s1, ans);
+ }
+ else
+ copyMostAttrib...