Displaying 20 results from an estimated 8000 matches similar to: "Matrix operations in a list"
2013 Apr 13
2
Comparison of Date format
Hi,
?In the example you provided, it looks like the dates in Date2 happens first.? So, I changed it a bit.?
DataA<- read.table(text="
ID,Status,Date1,Date2 ??? ??? ??????
1,A,3-Feb-01,15-May-01 ??? ???
1,B,15-May-01,16-May-01 ??? ???
1,A,16-May-01,3-Sep-01 ??? ??? ??? ??? ???
1,B,3-Sep-01,13-Sep-01 ??? ??? ??? ??? ???
1,C,13-Sep-01,26-Feb-04 ??? ??? ??? ??? ???
2006 Jul 19
4
Wrap a loop inside a function
I need to wrap a loop inside a function and am having a small bit of
difficulty getting the results I need. Below is a replicable example.
# define functions
pcm <- function(theta,d,score){
exp(rowSums(outer(theta,d[1:score],'-')))/
apply(exp(apply(outer(theta,d, '-'), 1, cumsum)), 2, sum)
}
foo <- function(theta,items, score){
like.mat <-
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
2013 Feb 17
6
histogram
HI Elisa,
You could use ?cut()
vec1<-c(33,18,13,47,30,10,6,21,39,25,40,29,14,16,44,1,41,4,15,20,46,32,38,5,31,12,48,27,36,24,34,2,35,11,42,9,8,7,26,22,43,17,19,28,23,3,49,37,50,45)
label1<-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) x),lapply(seq(5,50,5),function(x) x),SIMPLIFY=FALSE),function(i) paste(i[1],"<x<=",i[2],sep="")))
2012 Dec 06
1
Vectorizing integrate()
I have written a program to solve a particular logistic regression problem using IRLS. In one step, I need to integrate something out of the linear predictor. The way I'm doing it now is within a loop and it is as you would expect slow to process, especially inside an iterative algorithm.
I'm hoping there is a way this can be vectorized, but I have not found it so far. The portion of code
2004 Jun 01
1
swapping with data.frame
Hi there,
I have some data which are convenient to enter as lists. For example:
t1<-list(fname="animal1",testname="hyla",dspkr="left",res1=39.7,res2=15.0)
t2<-list(fname="animal1",testname="bufo",dspkr="left",res1=14.4,res2=56.1)
2013 Feb 01
29
cumulative sum by group and under some criteria
Thank you very much for your reply. Your code work well with this example.
I modified a little to fit my real data, I got an error massage.
Error in split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) :
Group length is 0 but data length > 0
On Thu, Jan 31, 2013 at 12:21 PM, arun kirshna [via R] <
ml-node+s789695n4657196h87@n4.nabble.com> wrote:
> Hi,
> Try this:
>
2006 Aug 18
1
multivariate analysis by using lme
Dear R users,
I have a data structure as follows:
id two res1 res2 c1 c2 inter
1 -0.786093166 1 0 1 2 6
3 -0.308495749 1 0 0 1 2
5 -0.738033048 1 0 0 0 1
7 -0.52176252 1 0
2006 Aug 30
4
Create a vector from another vector
Dear list
Suppose I have the following vector:
x <- c(3,4,2,5,6)
Obviously, this sums to 20. Now, I want to have a second vector, call it
x2, that sums to x where 5 <= x <= 20, but there are constraints.
1) The new vector must be same length as x
2) No element of the new vector can be 0
3) Element x2[i] of the new vector cannot be larger than element x[i] of
the original vector
4)
2012 Jan 04
1
function in R for my exercise
Hi R helpers!
I have a question. I'm trying to create a function for an exercise. Here are
the arguments I should include:
x and y are numeric
z is a name ("plus","minus","multiply","divide")
and swap is logical.
Here is what the function should do:
When z="plus", then x+y is performed and so on for the other z names. It
should give a NA
2006 Apr 19
4
Basic vector operations was: Function to approximate complex integral
Dear List
I apologize for the multiple postings. After being in the weeds on this
problem for a while I think my original post may have been a little
cryptic. I think I can be clearer. Essentially, I need the following
a <- c(2,3)
b <- c(4,5,6)
(2*4) + (2*5) + (2*6) + (3*4) + (3*5) +(3*6)
But I do not know of a built in function that would do this. Any
suggestions?
-----Original
2013 May 07
4
how to calculate the mean in a period of time?
Hi,
Your question is still not clear.
May be this helps:
dat2<- read.table(text="
patient_id????? t???????? scores
1????????????????????? 0??????????????? 1.6
1????????????????????? 1??????????????? 2.6
1????????????????????? 2???????????????? 2.2
1????????????????????? 3???????????????? 1.8
2????????????????????? 0????????????????? 2.3
2?????????????????????? 2???????????????? 2.5
2013 Jun 10
4
Combining CSV data
Hello R community,
I am trying to combine two CSV files that look like this:
File A
Row_ID_CR, Data1, Data2, Data3
1, aa, bb, cc
2, dd, ee, ff
File B
Row_ID_N, Src_Row_ID, DataN1
1a, 1, This is comment 1
2a, 1, This is comment 2
3a,
2003 Aug 21
4
anova(lme object)
Hi,
I use lme to fit models like
R> res1 <- lme(y~A+B, data=mydata, random=~1|subject)
R> res2 <- lme(y~B+A, data=mydata, random=~1|subject)
(only difference between these two models are the
sequence in which the indep variables are written in
formula)
where y is continuous and A, B, and subject are
factors. To get ANOVA table I used
R> anova(res1)
R> anova(res2)
and found
2000 Jul 05
1
Tukey.aov with split-plot designs
I am using R 1.1 with Redhat 6.2 and RW 1.001 with Win98 (the upkey doesn't
work on my IBM either as has been previously reported by others).
The function aov doesn't return either the residuals or the residual
degrees of freedom for split-plot designs.
If you use the following code from Baron and Li's "Notes on the use of R
for psycology experiments and questionnaires"
2007 Jan 24
4
Replace missing values in lapply
I have some matrices stored as elements in a list that I am working
with. On example is provided below as TP[[18]]
> TP[[18]]
level2
level1 1 2 3 4
1 79 0 0 0
2 0 0 0 0
3 0 0 0 0
4 0 0 0 0
Now, using prop.table on this gives
> prop.table(TP[[18]],1)
level2
level1 1 2 3 4
1 1 0 0 0
2
3
2011 May 19
3
problem with optim()
Dear R-users,
I would like to maximize the function g above which depends on 4 parameters (2 vectors, 1 real number, and 1 matrix) using optim() and BFGS method. Here is my code:
# fonction to maximize
g=function(x)
{
x1 = x[1:ncol(X)]
x2 = x[(ncol(X)+1)]
x3 = matrix(x[(ncol(X)+2):(ncol(X)+1+ncol(X)*ncol(Y))],nrow=ncol(X),ncol=ncol(Y))
x4 = x[(ncol(X)+1+ncol(X)*ncol(Y)+1):length(x)]
2012 Nov 08
5
map two names into one
Thanks.
Yes. Your approach can identify:
Glaxy ace S 5830 and
S 5830 Glaxy ace
But you can not identify using same program:
Iphone 4S 16 G
Iphone 4S 16G
How should I solve both in same time.
Kind regards,Tammy
[[alternative HTML version deleted]]
2012 Nov 10
4
help on date dataset
Hi everybody,
I am beginer in R and I need your precious help.
I want to create a small function in R as in sas to retrieve date.
I have a file with data that import in R.
DATE PAYS nb_pays.ILI.
1 24/04/2009 usa 0
2 24/04/2009 usa 0
3 24/04/2009 Mexique 0
4 24/04/2009
2013 Aug 26
4
transform variables
Dear all!
I have a data frame composed by 13 columns (year, and 12 months). I want to
transform this data base in another like this
year month values
1901 1
1901 2
1901 3
.....
1901 12
1902 1
1902 2
....
1902 12
Is there a possibility to succeed that in R?
Thank you!
best regards!
CR
--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str.