Displaying 20 results from an estimated 10000 matches similar to: "Function not working"
2011 Jan 19
2
xyplot question
Hi all,
I had a weird problem with xyplot and I am wondering if anyone can help me figure out what's wrong here. Basically if I call xyplot() inside a function and I call quartz() after, then the previous xyplot() does not do anything. A short demo of the issue is like this:
library(lattice)
plot.trends <- function()
{
mat <- data.frame(cbind(rnorm(100), rnorm(100)))
names(mat)
2023 Mar 19
2
WISH: Optional mechanism preventing var <<- value from assigning non-existing variable
Why should it make an exception for cases where the about-to-be-assigned-to
name is present in the global environment? I think it should warn or give
an error if the altered variable is in any environment on the search list.
-Bill
On Sun, Mar 19, 2023 at 10:54?AM Duncan Murdoch <murdoch.duncan at gmail.com>
wrote:
> I think that should be the default behaviour. It's pretty late to
2023 Mar 19
1
WISH: Optional mechanism preventing var <<- value from assigning non-existing variable
I'd like to be able to prevent the <<- assignment operator ("super
assignment") from assigning to the global environment unless the
variable already exists and is not locked. If it does not exist or is
locked, I'd like an error to be produced. This would allow me to
evaluate expressions with this temporarily set to protect against
mistakes.
For example, I'd like to
2023 Mar 19
1
WISH: Optional mechanism preventing var <<- value from assigning non-existing variable
I think that should be the default behaviour. It's pretty late to get
that into R 4.3.0, but I think your proposal (with check.superassignment
= FALSE being the default) could make it in, and 4.4.0 could change the
default to TRUE.
Duncan
On 19/03/2023 12:08 p.m., Henrik Bengtsson wrote:
> I'd like to be able to prevent the <<- assignment operator ("super
>
2008 Oct 22
2
suboptimal lp solutions
Hi list,
I want to find the total maximum resources I can spend given a set
allocation proportion and some simple budget constraints.
However, I get suboptimal results via lp and friends (i.e. lpSolve and
simplex in the linprog and boot) .
For example:
library(lpSolve)
proportions = c( 0.46, 0.28, 0.26)
constraints = c( 352, 75, 171)
lp(objective.in = proportions,
const.mat =
2004 Dec 10
1
subset bug?
I ran into a problem with "subset" while working at home that I am not sure is a bug or not. I defined a custom function to take a data frame of tree positions, sizes, and types (containing the columns TRT, COMP, PLOT, X, Y, DBH and CON) and wanted to make a stem map of the plot using different symbols and colors to represent the different types of tree stems. I copied a bit of the
2004 Oct 08
2
Evaluating Assignment-Operator R 2.0.0
Dear Helpers,
in which way I have to use the assignment-operator evaluating left to right
with R 2.0.0?
With R 2.0.0 (w2k-installation) the "superassignment" operator '<<-' seems to
have a different behaviour compared with R 1.9.1 :
> x<<-4
> x
[1] 4
> attr(x,'y')<<-5
Error: Object "x" not found
>
Using earlier
2023 Jan 27
1
implicit loop for nested list
I would use replicate() to do an operation with random numbers repeatedly:
```
mysim <- replicate(10, {
two.mat <- matrix(rnorm(4), 2, 2)
four.mat <- matrix(rnorm(16), 4, 4)
list(two.mat = two.mat, four.mat = four.mat)
})
```
which should give you a matrix-list. You can slice this matrix-list
just like normal, then cbind it in one step:
```
two.mat <-
2011 Aug 21
1
Multiple R linear models into one Latex table
Dear community,
I had been looking for an easy way to produce latex tables from R
output. xtable() and the package apsrtable produce good outputs but they are not
exactly what I was looking for.
I wrote this code that generates regression tables from multiple R
linear models. I want to share it because it might be
useful for someone else, and because I would appreciate comments on how to
2023 Mar 19
1
WISH: Optional mechanism preventing var <<- value from assigning non-existing variable
I have to say <<- is a core debugging tool when assigning into the global
environment. I suppose I could use assign but that would be somewhat
annoying.
That said I'm still for this change, the vast overwhelming number of times
that <<- is in my package code - already rare but it does happen - it would
absolutely be a bug (typo most likely) for it to get to the global
environment
2007 Oct 24
1
Error in nls model.frame
Error in model.frame
When I run the following nls model an error message appears and I dont
know how to solve that. Could you help me??
mat = c(1,2,3,4,5,6,7,8,9,12,16,24,36,48,60)
for (i in 1:length(j30)) {
bliss = nls(c(j[i,1:length(mat)]) ~ b0 + b1*((1-exp(-k1*mat))/(k1*mat)) +
b2*(((1-exp(-k2*mat))/(k2*mat))-exp(-k2*mat)),
start = list(k1=0.1993, k2=0.1993, b0= 22.0046,
2009 Jul 15
1
Matrix multiplication precision
Hi!!
I am trying to multiply 5 matrices and then using the inverse of that matrix for further computation. I read about precision problems from the archives and the suggestion was to use as.numeric while computing the products. I am still having problems with the results. Here is how I am using it
#Mn.mat<-(T.mat %*% Rz.mat %*% Q.mat %*% Rz.mat %*% T.mat) # I was doing this in one step
2005 Aug 03
2
using weighted.mean with tapply()
I am trying to calculate the weighted mean for a of 10 deciles and I
get an error:
> decile <- tapply(X=mat$trt1m, INDEX=mat$Rank, FUN=weighted.mean, w=mat$mcap)
Error in FUN(X[[1]], ...) : 'x' and 'w' must have the same length
All three of my inputs have the same length, as shown below, and the
weighted.mean calculation works by itself, just not in tapply()
>
2017 Jan 19
2
Error en loop anidado con data.table
Hola tengo una tabla de tipo data.frame "datos" con la siguiente
estructura, simplificada en número de niveles por variable, para crear un
ejemplo más sencillo:
id anio t_8a t_10a t_12a rankf8 rankf10 rankf12
1 1 100 220 220 NA NA NA
2 1 140 350 350 NA NA NA
3 2 55 165 165 NA NA NA
4 2 60 200 200 NA NA NA
5 2 100 NA NA NA NA NA
6 3 NA 350 350 NA NA NA
También tengo una matriz,
2023 Jan 27
3
implicit loop for nested list
>
> I am looking for a more elegant way to write below code.
>
> #Simulation results have different dimensions
> mysim <- lapply(1:10, function(y) {
> two.mat <- matrix(rnorm(4), nrow = 2)
> four.mat <- matrix(rnorm(16), nrow = 4)
> list(two.mat = two.mat, four.mat = four.mat) #results with different dimensions
> })
>
> #Collect different
2007 Jun 06
1
error message: only first element in each line of matrix used
I have a matrix and am trying to write a code to
1. identify all neg values along each line
2. for each neg value I need to identify min(j+3)
3. end with this code: eq[i,j]<- ifelse(mat.r[i,j] < (0.5*mat.s[i,j]), mat.all[i,j], 0)
This is the code I have so far. I have tried several different methods but I
keep getting the same error message that the condition has length >1 and
only
2006 Jul 20
2
Timing benefits of mapply() vs. for loop was: Wrap a loop inside a function
List:
Thank you for the replies to my post yesterday. Gabor and Phil also gave
useful replies on how to improve the function by relying on mapply
rather than the explicit for loop. In general, I try and use the family
of apply functions rather than the looping constructs such as for, while
etc as a matter of practice.
However, it seems the mapply function in this case is slower (in terms
of CPU
2004 Jul 02
2
Error:length of dimnames [2] not equal to array extent ?
Hi everyone,
I have the following problem:
I want to perform a LDA with the function lda().
My data object mat.data is a matrix with dimensions
> dim(mat.data)
[1] 1228 44
and my grouping vector grp has length 1228:
> length(grp)
[1] 1228
Every time I call lda(), the following error message occurs:
> lda(mat.data,grp)
Error in lda.default(x, grouping, ...) : length of dimnames [2]
2011 Nov 27
1
generating a vector of y_t = \sum_{i = 1}^t (alpha^i * x_{t - i + 1})
Dear R-help,
I have been trying really hard to generate the following vector given
the data (x) and parameter (alpha) efficiently.
Let y be the output list, the aim is to produce the the following
vector(y) with at least half the time used by the loop example below.
y[1] = alpha * x[1]
y[2] = alpha^2 * x[1] + alpha * x[2]
y[3] = alpha^3 * x[1] + alpha^2 * x[2] + alpha * x[3]
.....
below are
2000 Mar 14
1
qr.solve (fwd)
Two friend reported me a problem, which I can't solve:
(I run R-1.0.0, Debian Linux)
They hava a function "corr.matrix" (see end of mail), and when they
create a 173x173 matrix with this function
V <- corr.matrix(0.3, n=173)
V1 <- qr.solve(V)
reports:
Error in qr(a, tol = tol) : NA/NaN/Inf in foreign function call (arg 1)
For n < 173, qr.solve returns the correct