Displaying 20 results from an estimated 10000 matches similar to: "calculating column difference in a matrix"
2007 May 11
3
how to get column/row info from a dist object?
Dear R users;
Is it possible to get the row and column number of a particular entry
in a dist object?
Let's say that I want to find the position of the value 1.1837 (the
last entry on the dist object below), that is [6,3]. Can I get those
values without transforming the object to a matrix?, i.e. working with
the dist object only.
1 2 3
2 0.23935864
2016 Apr 02
3
apply mean function to a subset of data
Dear all;
This must have a rather simple answer but haven't been able to figure it
out: I have a data frame with say 2 groups (group 1 & 2). I want to select
from group 1 say "n" rows and calculate the mean; then select "m" rows from
group 2 and calculate the mean as well. So far I've been using a for loop
for doing it but when it comes to a large data set is
2016 Apr 03
1
apply mean function to a subset of data
Here are several ways to get there, but your original loop is fine once it is corrected:
> for (i in 1:2) smean[i] <- mean(toy$diam[toy$group==i][1:nsel[i]])
> smean
[1] 0.271489 1.117015
Using sapply() to hide the loop:
> smean <- sapply(1:2, function(x) mean((toy$diam[toy$group==x])[1:nsel[x]]))
> smean
[1] 0.271489 1.117015
Or use head()
> smean <- sapply(1:2,
2016 Apr 02
0
apply mean function to a subset of data
Hi Pedro,
This may not be much of an improvement, but it was a challenge.
selvec<-as.vector(matrix(c(nsel,unlist(by(toy$diam,toy$group,length))-nsel),
ncol=2,byrow=TRUE))
TFvec<-rep(c(TRUE,FALSE),length.out=length(selvec))
toynsel<-rep(TFvec,selvec)
by(toy[toynsel,]$diam,toy[toynsel,]$group,mean)
Jim
On 4/3/16, Pedro Mardones <mardones.p at gmail.com> wrote:
> Dear all;
>
2007 Jun 14
4
question about formula for lm
Dear all;
Is there any way to make this to work?:
.x<-rnorm(50,10,3)
.y<-.x+rnorm(50,0,1)
X<-data.frame(.x,.y)
colnames(X)<-c("Xvar","Yvar")
Ytext<-"Yvar"
lm(Ytext~Xvar,data=X) # doesn't run
lm(Yvar~Xvar,data=X) # does run
The main idea is to use Ytext as input in a function, so you just type
"Yvar" and the model should fit....
2011 Sep 20
5
help in interpreting paired t-test
Dear all;
A very basic question. I have the following data:
************************************************************************************
A <- 1/1000*c(347,328,129,122,18,57,105,188,57,257,53,108,336,163,
62,112,334,249,45,244,211,175,174,26,375,346,153,32,
89,32,358,202,123,131,88,36,30,67,96,135,219,122,
89,117,86,169,179,54,48,40,54,568,664,277,91,290,
2009 Mar 14
4
persp plot + plotting grid lines
Dear all;
Does anyone know how to add grid lines to a persp plot? I've tried
using lines(trans3d..) but the lines of course are superimposed into
the actual 3d surface and what I need is something like the plot shown
in the following link:
http://thermal.gg.utah.edu/tutorials/matlab/matlab_tutorial.html
I'll appreciate any ideas
Thanks
PM
2009 Jan 18
2
don't print object attributes on screen
Dear all;
I have a function written in R that returns as a list of values as
output that has associated some user defined attributes to it. How can
hide these attributes when printing the output on screen? I'm using
R-2.8.1 on WinXP....it's like hiding the attr of the output from the
scale function....
Thanks in advance
PM
2008 Jan 29
2
error message + boot library
Dear all;
What can be wrong with this simple example?
library(boot)
d1<-c(rnorm(10,mean=10))
fm<-function(d,i) mean(d[i])
bd1<-boot(d1,fm,10000)
> Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Thanks for any idea
2006 Nov 29
3
R2.4 xyplot + panel.number problem
Hi all;
I'm trying to display a 2 panel plot for the Puromycin data from R
with 2 different non-linear models fitted to each group. The problem
is that as far as I know panel.number doesn't work in the latest
version of R. Can anyone give a hint how to solve this?
Here is the code that I used before and now doesn't work
xyplot(rate ~conc| state,Puromycin,
2006 Dec 26
2
sequential row selection in dataframe
Dear all;
I'm wondering if there is any 'efficient' approach for selecting a
sample of 'every nth rows' from a dataframe. For example, let's use
the dataframe GAGurine in MASS library:
> length(GAGurine[,1])
[1] 314
# select an 75% of the dataset, i.e. = 236 rows, every 2 rows starting
from row 1
> test<-GAGurine[seq(1,314,2),]
> length(test[,1])
[1] 157
#
2008 Apr 08
1
plot function / par() settings
Dear all;
I'm trying to create a 2 x 3 plot (something I know like lattice can
do better) using the plot function. However; I'm not sure how to make
the width of the plots to be the same on each column. I guess the
answer maybe obvious but I haven't been able to figure it out. I'll
appreciate any suggestion. Here is the (highly inefficient) code for
the first row:
par(mfrow =
2018 Jan 30
2
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
Hi Martin, Henrik,
Thanks for the follow up.
@Martin: I vote for 2) without *any* hesitation :-)
(and uniformity could be restored at some point in the
future by having prod(), rowSums(), colSums(), and others
align with the behavior of length() and sum())
Cheers,
H.
On 01/27/2018 03:06 AM, Martin Maechler wrote:
>>>>>> Henrik Bengtsson <henrik.bengtsson at gmail.com>
2007 Nov 06
2
translating R code to C code
I would like to try to implement a big series of nested loops in a C
code and then call it from R; however I'm not familiar with C
programming. Does anyone know about some sort of reference I can use
that help me to translate my code to C? (I'm thinking on something
like to Octave to R reference posted in CRAN)
thanks
PM
2008 Jun 23
1
levelplot question
Dear all;
I have a data set with 3 groups and 2 response variables, say z1 and
z2, and I would like to create a single plot (using the levelplot
function) showing on the first row the leveplots for z1 for each group
and on the second row levelplots for z2 for the same groups. I tried
plot.trellis using the split option and it's OK but what I would like
to achieve is something similar to what
2006 Oct 22
1
least median squares
Does anyone can provide a code to implement least median squares
regression in R (not using the lqs function or calling C functions)?
Reason: teaching/learning purposes
Thanks
PM
2017 Apr 01
1
mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds
On Fri, Mar 31, 2017 at 10:14 PM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:
> From ?NA
>
> Numerical computations using ?NA? will normally result in ?NA?: a
> possible exception is where ?NaN? is also involved, in which case
> either might result.
>
> and ?NaN
>
> Computations involving ?NaN? will return ?NaN? or perhaps ?NA?:
>
2018 Jan 25
2
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
Just following up on this old thread since matrixStats 0.53.0 is now
out, which supports this use case:
> x <- rep(TRUE, times = 2^31)
> y <- sum(x)
> y
[1] NA
Warning message:
In sum(x) : integer overflow - use sum(as.numeric(.))
> y <- matrixStats::sum2(x, mode = "double")
> y
[1] 2147483648
> str(y)
num 2.15e+09
No coercion is taking place, so the
2014 Sep 30
2
Shallow copies
I have a question about shallow copies in R. Since R 3.1.0, subsetting
a dataframe with respect to its columns no longer result in deep
copies. This is an amazing change in my opinion. Now, subsetting a
data.frame by rows (or subsetting a matrix by columns or rows) still
does deep copies. In particular, it is my understanding that running a
command on a very large subset of rows (say
2012 Sep 16
1
trying to obtain same nls parameters as in example
Dear R-users;
I'm working with a a dataset that was previously used to fit a
nonlinear model of the form:
Y ~ a * (1 + b * log(1 - c * X^d))
The parameters published elsewhere are:
a = 1.758863, b = .217217, c = .99031, and d = .054589
However, there is no way I can replicate this result. I've tried
several options (including SAS) w/o success.
The data is:
X <-