Hello,
I am trying to reshape a data.frame in wide format into long format.
Although in the reshape R documentation
they programmer list some examples I am struggling to bring my data.frame
into long and then transform it back into wide format. The data.frame I look
at is:
df - data.frame(ID1
library(reshape2)
melt(df, id.vars = c(ID1, ID2, ID3))[, -4]
# To drop an extraneous column (but you should take a look and see
what it is for future reference)
Michael
On Tue, Mar 6, 2012 at 6:17 AM, mails mails00...@gmail.com wrote:
Hello,
I am trying to reshape a data.frame in wide
] On Behalf Of R. Michael Weylandt
Sent: Tuesday, March 06, 2012 8:45 AM
To: mails
Cc: r-help@r-project.org
Subject: Re: [R] Help on reshape function
library(reshape2)
melt(df, id.vars = c(ID1, ID2, ID3))[, -4]
# To drop an extraneous column (but you should take a look and see
what
Hey Michael,
thanks for your help. I think the reshape2 library works much better than
the normal reshape function.
However, I still cannot retransform my data.frame into wide format once used
melt function to transform
it into long format. How do I get it back to wide format?
The documentation,
You'll need to use the cast() function but I can't say more unless you
can provide more specifics. I believe Hadley's website has more
documentation than the package: http://had.co.nz/reshape/
Michael
On Tue, Mar 6, 2012 at 9:34 AM, mails mails00...@gmail.com wrote:
Hey Michael,
thanks for
On Mar 6, 2012, at 12:45 PM, R. Michael Weylandt wrote:
You'll need to use the cast() function but I can't say more unless you
can provide more specifics. I believe Hadley's website has more
documentation than the package: http://had.co.nz/reshape/
in reshape2 Hadley did away with cast() and
Dear R users, I am trying to use apply function on a 3D array (get rid of any
loop) but wasn't successfull. Below is a toy example of what I am trying to do:
refID_remNoCat = 1:30;
s_remNoCat = sample(1:length(refID_remNoCat),size=length(refID_remNoCat));
s.sort_remNoCat =
Hi
I'm getting the intercepts of the Random effects as 0. Please help me to
understand why this is coming Zero
This is my R code
Data- read.csv(C:/FE and RE.csv)
Formula=Y~X2+X3+X4 + (1|State) + (0+X5|State)
fit=lmer(formula=Formula,data=Data)
ranef(fit).
My sample Data
State YearY
Hi,
I'm trying to plot a set of geographical coordinates over the polygons in a
shapefile, so I need to transform the coordinates to the same projection.
I'm currently using the project function in the rgdal library, but I can't
seem to figure out how to format the proj string argument correctly.
Hi Everyone,
Can anyone help me resolve a problem that i'm having with nlminb. The
problem is that it stops after just one iteration and returns the same
values as start ones.
Thank you very much for your help.
Sincerely.
--
Kamel Gaanoun
(+33) (0)6.76.04.65.77
[[alternative
Is the room still a room when its empty? Does the room,
the thing itself have purpose? Or do we, what's the word... imbue it.
- Jubal Early, Firefly
r-help-boun...@r-project.org wrote on 12/15/2010 08:53:39 AM:
[image removed]
[R] Help about nlminb function
kamel gaanoun
:
[image removed]
[R] Help about nlminb function
kamel gaanoun
to:
r-help
12/15/2010 08:56 AM
Sent by:
r-help-boun...@r-project.org
Hi Everyone,
Can anyone help me resolve a problem that i'm having with nlminb. The
problem is that it stops after just one
kamel gaanoun kamel.gaanoun at gmail.com writes:
I appologize for the lack of information in my previous mail, but it is my
first one.
Yes I red -in part- the Port documentation to learn what does the message
X-convergence (3) mean.
so this is my nlminb and the results :
... imbue it.
- Jubal Early, Firefly
kamel gaanoun kamel.gaan...@gmail.com wrote on 12/15/2010 09:22:57 AM:
[image removed]
Re: [R] Help about nlminb function
kamel gaanoun
to:
Jonathan P Daily
12/15/2010 09:23 AM
Cc:
r-help, r-help-bounces
I appologize for the lack
it.
- Jubal Early, Firefly
kamel gaanoun kamel.gaan...@gmail.com wrote on 12/15/2010 09:22:57 AM:
[image removed]
Re: [R] Help about nlminb function
kamel gaanoun
to:
Jonathan P Daily
12/15/2010 09:23 AM
Cc:
r-help, r-help-bounces
I appologize for the lack
Hi, when I need to download some package I use for example
install.packages(fBasics) function. However simply using that function
needs additional intervention to select the server from which I want to
download. I would like to ask the list how I can put additional argument in
the
Hi Chistofer,
I selected a mirror in my .Rprofile file (which I think is fairly
common), so I do not have to set it every time I start R. In any
case, you just have to specify the url of the mirror you want to the
CRAN repo. Something like this ought to work:
r - getOption(repos)
r[CRAN] -
Hi:
Try
str(u.ts)
class(u.ts)
That should give you more information about the type of object being input
to stl.
I tried the following, which worked on my system:
u - rnorm(100)
u.ts - ts(u, start = c(2001, 1), frequency = 12)
u.stl - stl(u.ts, 'per')
plot(u.stl)
sessionInfo()
R version
Hi everyone.
I'm having some troubles with STL function to decompose some data.
My issue is that I have monthly data from September 2005 up to August 2010
i. e. 60 observations.
I define it in the following way:
*u-read.csv(C:/CELEBREX.csv,header = TRUE)
u.ts-ts(u, start=c(2005,9),
Hi
I am using the ugarchspec function from the rgarch package to fit a mean
variance model jointly. Following is the code I'm using:
spec = ugarchspec(variance.model = list(model=eGARCH,
garchOrder=c(1,1)), mean.model = list(armaOrder=c(1,1)))
On doing this, I get the following error:
Error
iterations - 100
nvars - 4
combined - rbind(scaleMiceTrain, scaleMiceTest)
reducedSample - combined
reducedSample - subset(reducedSample, select = -pID50)
reducedSample - subset(reducedSample, select = -id)
for (i in 1:iterations)
{
miceSample - sample(combined[,-c(1,2)],nvars,
This is not reproducible, and does not look minimal. You'll get better
answers, and probably solve many issues on your own, if you construct
small examples that illustrate the same problem you're having with your
real data.
Addi Wei wrote:
iterations - 100
nvars - 4
combined -
Sorry about that. Still new to this... The code below should be
reproducible.All R2 should just be 1, and I should write 1 to
R2outputKKNN.txt 10 timesnothing is happening. Appreciate the efforts
to help!
for (i in 1:10)
{
adata = 1:5
bdata = 6:10
lm -
Your code between calls to sink() does not generate any output. Hence,
nothing will be diverted to the file. To illustrate this point,
consider
for(i in 1:10) i
This produces no output. However,
for(i in 1:10) print(i)
produces output as expected.
-Matt
On Fri, 2010-07-16 at 13:34 -0400,
.
-Aadhithya
--
View this message in context:
http://r.789695.n4.nabble.com/help-on-naivebayes-function-in-R-tp2272720p2272720.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman
where I am going wrong. I want the confusion matrix using
table function but I am not able to get it . Please help me . I will be
really grateful .Thanks in advance.
-Aadhithya
--
View this message in context:
http://r.789695.n4.nabble.com/help-on-naivebayes-function-in-R-tp2272720p2272720.html
Hello,
Try this, it is based off of your sample wide format data. I am not
quite sure how you got the 'gene1' column in your desired output data,
it looks like it is just the data from patient1, but since I was not
sure, I did not include it.
##
temp -
Xin Wei
I have sympathy with your difficulties in understanding the reshape()
function.
May I recommend using the melt() and cast() functions instead, available in
the reshape package. You can find information, help and examples here:
http://had.co.nz/reshape/
This simplifies the coding of
hi, everyone:
i have a question on the reshape function. i have the following dataset :
gene tissuepatient1 patient2 patient3.
_
gene1 breast 10 20 50
gene2 breast 20 40 60
gene3
Try this:
reshape(x, direction = 'long', varying = list(3:5), timevar = gene,
v.names = value)
On Thu, Jun 17, 2010 at 3:22 PM, xin wei xin...@stat.psu.edu wrote:
hi, everyone:
i have a question on the reshape function. i have the following dataset :
gene tissuepatient1 patient2
I am afraid that your solution is not solving the problem. it seems that
timevar=gene just create the followings:
GENESAMPLE value id
1.11 Kidney 3.69351 1
2.11 Kidney 5.42710 2
3.11 Kidney 5.26883 3
4.11 Kidney 2.88098 4
5.11 Kidney 4.68519
Hello,
I'm trying to calculate non-parametric probabilities using the np package
and having some difficulties.
OS is Windows, R version 2.11.1
Here is what I've done so far.
library(np)
veg - data.frame(factor(Physiogomy), meanAnnualDepthAve, TP)
attach(veg) : for clarification dim(veg)
On 07/04/2010 4:24 PM, Changbin Du wrote:
Hi, r-community,
This morning, I MET the following problem several times when I try to attach
the data set.
When I closed the current console and reopen the R console, the problem
disappear. BUt with the time passed on, the problem occurs again.
Can
Thanks so much! Duncan, I appreciated!
On Thu, Apr 8, 2010 at 5:03 AM, Duncan Murdoch murd...@stats.uwo.ca wrote:
On 07/04/2010 4:24 PM, Changbin Du wrote:
Hi, r-community,
This morning, I MET the following problem several times when I try to
attach
the data set.
When I closed the
Hi, r-community,
This morning, I MET the following problem several times when I try to attach
the data set.
When I closed the current console and reopen the R console, the problem
disappear. BUt with the time passed on, the problem occurs again.
Can anyone help me with this?
attach(total)
Hi,
On Wed, Apr 7, 2010 at 4:24 PM, Changbin Du changb...@gmail.com wrote:
Hi, r-community,
This morning, I MET the following problem several times when I try to attach
the data set.
When I closed the current console and reopen the R console, the problem
disappear. BUt with the time passed
You can also read the help page for the conflicts() function. And try
a commend like
find('acid')
(or any of the objects listed as being masked)
to find out where the two or more objects with the same name are located.
Oh, and looking at ?search would be good also.
-Don
At 4:31 PM -0400
The unstack function is a bit clumsy for this problem:
library(MASS)
cbind(Treatment = unstack(Rabbit, Treatment ~ Animal)[,1],
Dose = unstack(Rabbit, Dose ~ Animal)[,1],
unstack(Rabbit, BPchange ~ Animal))
A much better choice would be to use the reshape package:
require(reshape)
Hi Everyone,
I am trying to understand the unstack() function but after struggling for
two days, I have given up. More specifically, I am trying the exercises at
the end of Chapter 1 of Data Analysis and Graphics Using R by Maindonald
and Braun, 2nd ed. Exercise 18 (p. 41) asks to unstack the
I have some data in my C code, I want to execute chi-square test on those
data. I tried implementing pchisq() function making use of header files R.h,
Rhead.H and Rinternals.h, but it neither gave me the result nor threw any
errors. It just returned 0 or 1.
Could you please help me how can I
Thanks David,
Yes, I am talking about the MASS package.Thank you for pointing out that
these scale the same. My question is, how do I get from the V1 data:
V1
1 164.4283
2 166.2492
3 170.5232
4 156.5622
5 127.7540
6 136.7704
7 136.3436
to the other set of data:
+ 1 -2.3769280
+ 2
If you want to see how Venables and Ripley get their lda distances,
then this is a quick path to the (uncommented) source:
1) methods(lda)
[1] lda.data.frame* lda.default*lda.formula*lda.matrix*
2) since you call involved a formula I looked first at:
getAnywhere(lda.formula)
A single
I am having a problem understanding the lda package. I have a dataset here:
[,1] [,2] [,3]
[1,] 2.95 6.630
[2,] 2.53 7.790
[3,] 3.57 5.650
[4,] 3.16 5.470
[5,] 2.58 4.461
[6,] 2.16 6.221
[7,] 3.27 3.521
If I do the following;
names(d)-c(y,x1,x2)
d$x1 = d$x1 * 100
Your results are the same (after scaling and sign reversal) out to the
4th decimal place as those from lda (which by the way is almost
certainly from the MASS package and not from an impossible to find
lda package.)
read.table(textConnection(txt))
V1
1 164.4283
2 166.2492
3
Dear All,
I am attempting to use R to perform an ANOVA with three factors:
feature (3 levels), group (5 levels), and patient (246 levels), where
patient is nested within group.
Currently I am using the lm function to fit the model, with the
following form:
fit - lm(intensity ~ feature
Hi,
I´ve got a problem with using the pmvnorm function.
For example ,if i assume a bivariate normal distribution with mean=(0,0) and
sigma=(1,0.5,0.5,1)
how do i generate the probability for X1=2 and X2=3 ?
--
View this message in context:
I have a misunderstanding on the residuals function in 'R'. In the stats
package the residuals for the output of a HoltWinters fit is
residuals.HoltWinters and the source looks like:
stats:::residuals.HoltWinters
function (object, ...)
object$x - object$fitted[, 1]
environment:
Vaupo- I think that
pmvnorm(lower=-Inf*c(1,1),upper=c(2,3),corr=sigma)
does what you want.
Ron
Vaupo wrote:
Hi,
I´ve got a problem with using the pmvnorm function.
For example ,if i assume a bivariate normal distribution with mean=(0,0) and
sigma=(1,0.5,0.5,1)
how do i generate the
On Tue, Aug 18, 2009 at 8:13 AM, Frank E Harrell
Jrf.harr...@vanderbilt.edu wrote:
Noah Silverman wrote:
Hi,
I'm developing an experiment with logistic regression.
I've come across the lrm function in the Design library.
While I understand and can use the basic functionality, there are a
Hi,
I'm developing an experiment with logistic regression.
I've come across the lrm function in the Design library.
While I understand and can use the basic functionality, there are a ton
of options that go beyond my knowledge.
I've carefully read the help page for lrm, but don't
Hi,
I'm developing an experiment with logistic regression.
I've come across the lrm function in the Design library.
While I understand and can use the basic functionality, there are a ton
of options that go beyond my knowledge.
I've carefully read the help page for lrm, but don't
-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Noah Silverman
Sent: Monday, August 17, 2009 5:21 PM
To: r help
Subject: [R] Help understanding lrm function of Design library
Hi,
I'm developing an experiment with logistic regression.
I've come across the lrm function
Hi Noah,
Could someone point me to an online resource where I could learn
more? (I'm big on trying to teach myself.) [about lrm funcction and the
Design library]
Go for the hardcopy, but you could look at Google Books if you are pressed.
There you will find a good preview of the text. Also
Noah Silverman wrote:
Hi,
I'm developing an experiment with logistic regression.
I've come across the lrm function in the Design library.
While I understand and can use the basic functionality, there are a ton
of options that go beyond my knowledge.
I've carefully read the help page for
Dear all,
I have a task to find the first all zero row of a matrix X ( nothing known
about X). I need to write a function which returns either the row index of
the first all-zero row, or NA if there are no all-zero rows. and I also need
to locate all rows which are non-zero (should be a vector of
Try this:
x - matrix(1:40,ncol=5)
# function to find zero rows
f.zero -
+ function(arr)
+ {
+ which(apply(arr, 1, function(z) all(z == 0)))[1] # first one
+ }
# now the non-zero rows
f.nonzero -
+ function(arr)
+ {
+ which(apply(arr, 1, function(z) any(z != 0)))
+ }
f.zero(x)
[1]
Dear R users,
I'm using Ecdf (Hmisc library) to plot four cdf in a same graphic. In this
graphic I also plot the 0.99 quantile for these cdf. I successfully plot
cdfs using different types of line to distinguish them, but I can't
determine the type of lines showing 0.99 quantile.
Is there a way
On Aug 3, 2009, at 4:19 PM, Mateus Teixeira wrote:
Dear R users,
I'm using Ecdf (Hmisc library) to plot four cdf in a same graphic.
In this
graphic I also plot the 0.99 quantile for these cdf.
How did you do this? Experimenting with the example on hte Ecdf help
page it appears that
David,
Actually, I have used the example given in Ecdf help page, see below a part
of the script:
comparacao-c(obs,simul[,,1],simul[,,2],simul[,,3],simul[,,4])
grupos-c( rep('obs',length(obs)), rep('exp1',length(simul[,,1])),
rep('exp2',length(simul[,,2])), rep('exp3',length(simul[,,3])),
Hi all, can you please clarify me what is the wrong with following codes :
set.seed(30)
z = matrix(rnorm(10), 5, 2)
apply(z, 1, function(x) sum(z[x,1]*1, z[x,2]*3))
However I can not get the desired result. For example, sum(z[1,1]*1,
z[1,2]*3) gives -5.822442 which is actually correct. Am I
You are indeed missing something. x is _one row_ of z, not the index
specifying that row. So what you want is:
apply(z, 1, function(x)sum(x[1]*1, x[2]*3))
Thanks for including a reproducible example.
Sarah
On Tue, Apr 28, 2009 at 9:02 PM, megh megh700...@yahoo.com wrote:
Hi all, can you
In the function call in 'apply', you are passed the values in the rows:
set.seed(30)
z = matrix(rnorm(10), 5, 2)
apply(z, 1, function(x) sum(z[x,1]*1, z[x,2]*3))
[1] -0.908321 0.00 0.00 -5.822442 -5.822442
z
[,1] [,2]
[1,] -1.2885182 -1.5113079
[2,] -0.3476894
Dear all:
I am using R function bwplot to plot box plots. I would like to change some
parameters of the typical box plots. For example, I would like to try different
types of whisker lines. I can use whiskerline=x in boxplot function but not in
bwplot function. Could you tell me how I can do
He, Yulei he at hcp.med.harvard.edu writes:
I am using R function bwplot to plot box plots. I would like to change some
parameters of the typical box
plots. For example, I would like to try different types of whisker lines. I
can use whiskerline=x in
boxplot function but not in bwplot
Hi R users,
Is is possible for me to use the try function with boot? I would to do
the bootstraping with a nonlinear model(it works well when R 1000).
But it does not work very well (when R is large) thus I try to use
try to resolve. I put the try function in two cases:
case1: put the
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Dear List,
I am trying to draw a rectangular plane using the persp function, however I
can't seem to get it to work. I want the length along x1 axis to be between
1 and 3 and the length along the x2 axis to be between 1 and 4. All z
values for x1 should be equal (say, z=1) because this is a
Is this what you want to do:
x - seq(from=1,to=3,by=.1)
y - seq(1,4,by=.1)
z - matrix(1, length(x), length(y))
persp(x=x,y=y,z,zlim=c(0,2))
On Sat, Aug 30, 2008 at 2:08 PM, dxc13 [EMAIL PROTECTED] wrote:
Dear List,
I am trying to draw a rectangular plane using the persp function, however I
Yes, this works nicely. Thank you!
jholtman wrote:
Is this what you want to do:
x - seq(from=1,to=3,by=.1)
y - seq(1,4,by=.1)
z - matrix(1, length(x), length(y))
persp(x=x,y=y,z,zlim=c(0,2))
On Sat, Aug 30, 2008 at 2:08 PM, dxc13 [EMAIL PROTECTED] wrote:
Dear List,
I am trying
Hi,
I would like to use the R's outer function on y below so that I can subtract
elements from each other. The resulting dataframe is symmetric, save for the
negative signs on the other half of the numbers. I would like to get only
half of the dataframe. Here is the code I wrote (it is returning
On Sun, Aug 10, 2008 at 09:02:59AM -0700, warthog29 wrote:
Hi,
I would like to use the R's outer function on y below so that I can subtract
elements from each other. The resulting dataframe is symmetric, save for the
^^
outer() returns a matrix,
On Sun, Aug 10, 2008 at 06:00:21PM +0100, Dan Davison wrote:
On Sun, Aug 10, 2008 at 09:02:59AM -0700, warthog29 wrote:
Hi,
I would like to use the R's outer function on y below so that I can subtract
elements from each other. The resulting dataframe is symmetric, save for the
Thanks Dan. You did much more than just answer my question.
Sincerely,
Dan Davison wrote:
On Sun, Aug 10, 2008 at 06:00:21PM +0100, Dan Davison wrote:
On Sun, Aug 10, 2008 at 09:02:59AM -0700, warthog29 wrote:
Hi,
I would like to use the R's outer function on y below so that I can
Hi
I've used the integrate function to do numerical integration and was
wondering exactly how the algorithm works. It states that it is adaptive
quadrature, does anyone know how the sampling points and weights are
chosen, and what transformation is used to convert infinite intervals
into finite
Hi All,
Is there a way to omit the variables in the graphical output of the biplot
function (so that only the categories are shown in the plot)? In addition does
the identify function work with the biplot function?
Thank you,
[[alternative HTML version deleted]]
times #
folds2-NULL
xy-as.data.frame(cbind(x,y))
for (i in 1:nrow(xy)) {
diff-xy$x[i]-xy$y[i]
folds2[i]-if(diff=0) {2^diff} else{-(2^abs(diff))}
}
xyz-cbind(xy,folds2)
View(xyz)
#
Thank you,
Alan
P.S. why does ?function not work
__
R
)) {
diff-xy$x[i]-xy$y[i]
folds2[i]-if(diff=0) {2^diff} else{-(2^abs(diff))}
}
xyz-cbind(xy,folds2)
View(xyz)
#
Thank you,
Alan
P.S. why does ?function not work
__
R-help@r-project.org mailing list
https://stat.ethz.ch
for 'function' here.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code
Hi Alan,
-Original Message-
From: [EMAIL PROTECTED] on behalf of ALAN SMITH
Sent: Tue 6/3/2008 6:47 PM
To: r-help@r-project.org
Subject: [R] help understanding why #function(x,y) (if((x-y)=0) {2^(x-y)}
else{-(2^abs(x-y))})# doesn't work likeI think it should
Hello R users
))
for (i in 1:nrow(xy)) {
diff-xy$x[i]-xy$y[i]
folds2[i]-if(diff=0) {2^diff} else{-(2^abs(diff))}
}
xyz-cbind(xy,folds2)
View(xyz)
#
Thank you,
Alan
P.S. why does ?function not work
__
R-help@r-project.org mailing list
https
I'm trying to build on Jim's approach to change the parameters in the
function, with new rules:
1. if (x[i]==0) NA
2. if (x[i]0) log(x[i]/(number of consecutive zeros preceding it +1))
x-c(1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
# i.e. output desired = c(0, NA, -0.69, NA, NA, -1.098, NA, NA, NA, -1.38,
I'm trying to build on Jim's approach to change the parameters in the
function, with new rules:
1. if (x[i]0) log(x[i]/(number of consecutive zeros immediately preceding
it +1))
2. if (x[i]==0) NA
x-c(1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
# i.e. output desired = c(0, NA, -0.69, NA, NA, -1.098, NA,
I'm trying to build on Jim's approach to change the parameters in the
function, with new rules:
1. if (x[i]==0) NA
2. if (x[i]0) log(x[i]/(number of consecutive zeros preceding it +1))
x-c(1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
# i.e. output desired = c(0, NA, -0.69, NA, NA, -1.098, NA, NA, NA,
I'm trying to build on Jim's approach to change the parameters in the
function, with new rules:
1. if (x[i]==0) NA
2. if (x[i]0) log(x[i]/(number of consecutive zeros immediately preceding
it +1))
x-c(1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
# i.e. output desired = c(0, NA, -0.69, NA, NA, -1.098,
Here's an added caveat, with subsequently a more detailed explanation of the
output desired:
The data this will apply to includes a variety of whole numbers not limited
to 1 0, a number of which may appear consecutively and not separated by
zeros!
e.g. x-c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
Here's an added caveat, with subsequently a more detailed explanation of the
output desired:
The data this will apply to includes a variety of whole numbers not limited
to 1 0, a number of which may appear consecutively and not separated by
zeros!
e.g. x-c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
I have a matrix of frequency counts from 0-160.
x-as.matrix(c(0,1,0,0,1,0,0,0,1,0,0,0,0,1))
I would like to apply a function creating a new column (x[,2])containing
values equal to:
a) log(x[m,1]) if x[m,1] 0; and
b) for all x[m,1]= 0, log(next x[m,1] 0 / count of preceding zero values
+1)
On Tue, 27 May 2008, T.D.Rudolph wrote:
I have a matrix of frequency counts from 0-160.
x-as.matrix(c(0,1,0,0,1,0,0,0,1,0,0,0,0,1))
I would like to apply a function creating a new column (x[,2])containing
values equal to:
a) log(x[m,1]) if x[m,1] 0; and
b) for all x[m,1]= 0, log(next x[m,1]
In fact x[4,2] should = log(x[5,1]/2]
whereas x[3,2] = log(x[5,1/3])
i.e. The denominator in the log function equals the number of rows between
m==0 and m0 (inclusive, hence the +1)
Hope this helps!...
Charles C. Berry wrote:
On Tue, 27 May 2008, T.D.Rudolph wrote:
I have a matrix
Does this do what you want:
x-c(0,1,0,0,1,0,0,0,1,0,0,0,0,1)
y - rle(x)
result - lapply(seq_along(y$lengths), function(.indx){
+ if (y$values[.indx] == 0)
log(y$values[.indx+1]/seq(y$lengths[.indx]+1, by=-1,
length=y$lengths[.indx]))
+ else rep(log(y$values[.indx]), y$lengths[.indx])
+
In fact x[4,2] should = log(x[5,1]/2]
whereas x[3,2] = log(x[5,1/3])
i.e. The denominator in the log function equals the number of rows between
m==0 and m0 (inclusive, hence the +1)
Hope this helps!
Charles C. Berry wrote:
On Tue, 27 May 2008, T.D.Rudolph wrote:
I have a matrix of
Hi there,
I am confused about fucntion call. After defining a function, I called it
within another function.
dt-cars; #a copy of R internal dataset cars created;
dt$cat1-ifelse(dt$speed20,0,1);
dt$ind-ifelse(dt$speed15,1,2); #group variable;
freqtot - function(data,var){
It isn't clear to me what output you would like to have by your
description.
However, there certainly is a clearer way of getting there than your
functions. If you better define what output you'd like to have (i.e.,
what your table should look like), I may be able to offer some suggestions.
Thanks for your help.
By adding { eval(substitute(var)) }, it works for me. Patrick advise me not
attaching a dataset in a function. I will try to avoid this.
Best,
Sean
On Tue, Mar 4, 2008 at 11:15 AM, Erik Iverson [EMAIL PROTECTED]
wrote:
It isn't clear to me what output you would like to
Dear lists,
Anysuggestion on how to write a loop function which has nx2 matrix as an
input, where each of the row represents an interval. the function should return
a mx2 matrix containing the no matched interval of x?? i've tried my own
function but it's only applies for 2x2 matrix.
Dears Sirs
During my computational work I encountered unexpected behaviour when calling
ar function.
I want to select the order p of the autoregressive approximation by AIC
criterion and sometimes an error occurs.
Example:
# time series
Hallo!
Have succeded in creating an image plot using image()
Have failed to provide explanation to what the colors means in terms of
values/numbers (i.e. the height of the staples that the colors represent).
Wonder if anyone have any help to offer in this matter? Have tried with
convertColor() and
Hi,
I try to use a substitute function to generalise a equation.
I have this:
expression(1+2*pred+3*lat)
I need to define the equation in function of x1 and x2 variables. Also I try
to define who is x1 and x2. I try this:
X1 - pred
X2 - lat
Now I need substitute pred and lat in equation by
Hi,
try this(Not tested):
substitute(expression(1+2*pred+3*lat),list(pred=as.name(x1),lat=as.name(x2)))
On 05/10/2007, Ronaldo Reis Junior [EMAIL PROTECTED] wrote:
Hi,
I try to use a substitute function to generalise a equation.
I have this:
expression(1+2*pred+3*lat)
I need to
On 10/5/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
Given this:
x1 - pred
x2 - lat
e - expression(1+2*pred+3*lat)
Try this:
L - list(as.name(x1), as.name(x2))
names(L) - c(x1, x2)
do.call(substitute, list(e, L)) # e L are evaluated first
or perhaps:
f - e
f - sub(pred, x1, f)
101 - 200 of 200 matches
Mail list logo