Displaying 20 results from an estimated 20000 matches similar to: "Alternative and more efficient data manipulation"
2011 Aug 16
1
Utilizing column names to multiply over all columns
## Hello there,
## I have an issue where I need to use the value of column names to
multiply with the individual values in a column and I have many
columns to do this over. I have data like this where the column names
are numbers:
mydf <- data.frame(`2.72`=runif(20, 0, 125),
`3.2`=runif(20, 50, 75),
`3.78`=runif(20, 0, 100),
yy=
2011 Jun 30
1
Italicized greek symbols in PDF plots
I know that this has been asked before in other variations but I just can't
seem to figure out my particular application from previous posts. My
apologies if I have missed the answer to this question somewhere in the
archives. I have indeed looked.
I am running Ubuntu 11.04, with R 2.12.1 and ESS+Emacs.
For journal formatting requirements, I need to italicize all the greek
letters in any
2010 Aug 17
3
predict.lm, matrix in formula and newdata
Dear all,
I am stumped at what should be a painfully easy task: predicting from an lm object. A toy example would be this:
XX <- matrix(runif(8),ncol=2)
yy <- runif(4)
model <- lm(yy~XX)
XX.pred <- data.frame(matrix(runif(6),ncol=2))
colnames(XX.pred) <- c("XX1","XX2")
predict(model,newdata=XX.pred)
I would have expected the last line to give me the
2009 Aug 20
1
how to compute this summation...
Dear R users,
I try to compute this summation,
http://www.nabble.com/file/p25054272/dd.jpg
where
f(y|x) = Negative Binomial(y, mu=exp(x' beta), size=1/alp)
http://www.nabble.com/file/p25054272/aa.jpg
http://www.nabble.com/file/p25054272/cc.jpg
In fact, I tried to use "do.call" function to compute each u(y,x) before the
summation, but I got an error, "Error in X[i, ]
2015 Oct 08
3
rank(, ties.method="last")
Hi,
I ran into a problem where I actually need rank(, ties.method="last"). It would
be great to have this feature in base and it's also simple to get (see below).
Thanks & cheers,
Marius
rank2 <- function (x, na.last = TRUE, ties.method = c("average",
"first", "last", # new "last"
"random", "max",
2004 Jun 15
1
R: slope estimations of teeth like data
On 15 Jun 2004 at 13:52, Vito Muggeo wrote:
> Dear Petr,
> Probably I don't understand exactly what you are looking for.
>
> However your "plot(x,c(y,z))" suggests a broken-line model for the
> response "c(y,x)" versus the variables x. Therefore you could estimate
> a segmented model to obtain (different) slope (and breakpoint)
> estimates. See
2004 Jun 15
3
slope estimations of teeth like data
Dear all
Suppose I have teeth like data similar like
x <- 1:200
y <- 0.03*x[1:100]+rnorm(100, mean=.001, sd=.03)
z <- 3-rep(seq(1,100,10),each=10)*.03+rnorm(100,mean=.001, sd=.03)
plot(x,c(y,z))
and I want to have a gradient estimations for some values from increasing part of
data
like
y.agg <- aggregate(diff(c(y,z)), list(rep(seq(1,200,10),each=10)[1:199]), mean)
y.agg[1:10,]
2011 Oct 22
1
Data frame manipulation by eliminating rows containing extreme values
Dear All,
I have got the limits for removing extreme values for each variables using
following function .
f=function(x){quantile(x, c(0.25, 0.75),na.rm = TRUE) - matrix(IQR(x,na.rm =
TRUE) * c(1.5), nrow = 1) %*% c(-1, 1)}
#Example:
n <- 100
x1 <- runif(n)
x2 <- runif(n)
x3 <- x1 + x2 + runif(n)/10
x4 <- x1 + x2 + x3 + runif(n)/10
x5 <-
2017 Sep 25
5
bowed linear approximations
Dear Rich,
Assuming that I understand what you want to do, try adding the following to your script (which, by the way, is more complicated that it needs to be):
xx <- 10:50
m <- lm(y ~ x)
yy <- predict(m, data.frame(x=xx))
lines(spline(xx, yy), col="blue")
m <- lm(y ~ log(x))
yy <- predict(m, data.frame(x=xx))
points(xx, yy, col="magenta")
The first set of
2004 Sep 15
2
efficient submatrix extraction
Hi,
I have a matrix of say 1024x1024 and I want to look at it in chunks.
That is I'd like to divide into a series of submatrices of order 2x2.
| 1 2 3 4 5 6 7 8 ... |
| 1 2 3 4 5 6 7 8 ... |
| 1 2 3 4 5 6 7 8 ... |
| 1 2 3 4 5 6 7 8 ... |
...
So the first submatrix would be
| 1 2 |
| 1 2 |
the second one would be
| 3 4 |
| 3 4 |
and so on. That is I want the matrix to be evenly divided
2017 Sep 26
0
bowed linear approximations
Hi Rich,
If I understand your comment about "uniformly distributed along the log=x
axis" then I think John's (second) set of commands needs a change to the
definition of xx, as follows:
xx <- exp(seq(from=log(min(x)),to=log(max(x)),length=50))
m <- lm(y ~ log(x))
yy <- predict(m, data.frame(x=xx))
points(xx, yy, col="red")
HTH,
Eric
On Mon, Sep 25, 2017 at
2009 Mar 13
1
malformed plot symbols in lattice pdf
Hi,
I'm using panel.polygon inside a custom panel function to generate
filled polygons for an xyplot. Everything is as expected until I
specify a value < 1 for alpha to fill with a semi-transparent color
and output to pdf. The plot symbols appear malformed. Am I doing
something wrong here?
Thanks,
Mark
Here is an example (pdfs are attached):
library(lattice)
## example data
2010 Jul 22
3
Hydrology plots in R
Hello,
I am trying to create a plot often seen in hydrodynamic work than includes a
contour plot representing the water speed with arrows pointing in the
direction of flow. Does anyone have any idea how I might add arrows based on
wf$angle (in the example below) to the plot below?
Thanks in advance!
Sam
library(lattice)
speed <- runif(100, 0, 20)
wf <- data.frame(speed)
wf$width <-
2010 Nov 17
2
Drop non-integers
Hello all,
I have a fairly simple data manipulation question. Say I have a dataframe
like this:
dat <- as.data.frame(runif(7, 3, 5))
dat$cat <- factor(c("1","4","13","1","4","13","13A"))
dat
runif(7, 3, 5) cat
1 3.880020 1
2 4.062800 4
3 4.828950 13
4 4.761850 1
5 4.716962 4
6
2005 Apr 01
1
optim problem, nls regression
Hi,
I try to fit a non linear regression by minimising the sum of the sum of
squares.
The model is number[2]-(x/number[1])^number[3]
Number [2] and number [1] change as the data changes but for all the set of
data number[3] must be identical.
I have 3 set of data (x1,y1), (x2,y2), (x3,y3).
x_a<-c(0,0.5,1,1.5,2,3,4,6)
y_a<-c(5.4,5,4.84,4.3,4,2,1.56,1.3)
2011 Oct 24
1
Adding points to a wireframe: 'x and units must have length >0' error
Hi,
I'm trying to follow the suggestions given by Deepayan Sarkar in this
message:
http://tolstoy.newcastle.edu.au/R/help/05/11/16135.html
to plot 3-D points on a wireframe plot. The problem is that I keep getting a
partly formed plot- with the colored lattice visible but no axis labels or
additional points- with the error message "error using packet 1, 'x' and
'units'
2005 Oct 05
8
R crashes for large formulas in lm() (PR#8180)
Full_Name: Hallgeir Grinde
Version: 2.1.1
OS: Windows XP
Submission from: (NULL) (144.127.1.1)
While using lm(y~(x*z*c*...*v)^2) R crashes/closes if the numbers of variables
are at least 8.
2012 Jan 19
3
Establishing groups using something other than ifelse()
Hello all,
This is one of those "Is there a better way to do this questions". Say
I have a dataframe (df) with a grouping variable (z). This is my base
data. Now I know that there is a higher order level of grouping that
exist for my group variable. So what I want to do is create a new
column that express that higher order level of grouping based on
values in the sub-group (z in this
2009 Sep 04
1
predicting from segmented regression
Hello
I'm having trouble figuring out how to use the output of "segmented()"
with a new set of predictor values.
Using the example of the help file:
??set.seed(12)
xx<-1:100
zz<-runif(100)
yy<-2+1.5*pmax(xx-35,0)-1.5*pmax(xx-70,0)+15*pmax(zz-.5,0)+rnorm(100,0,2)
dati<-data.frame(x=xx,y=yy,z=zz)
out.lm<-lm(y~x,data=dati)
o<-## S3
2003 Oct 05
3
stepAIC problem
Dear R-users
I have a probelm running stepAIC in R1.7.1
I wrote a program which used stepAIC as a part of it,
and it worked fine while I was using the previous version of
R1.7.0. However, I found the program did not work any more.
Now, R produces a message which tells
"Error in as.data.frame.default(data) :
can't coerce function into a data.frame" every time I
run the part of