Displaying 20 results from an estimated 2000 matches similar to: "select subset based on another variable"
2010 Aug 03
4
Need help on upper.tri()
HI, I am really messing up to make a symmetrical matrix using upper.tri() & lower.tri() function. Here is my code:
> set.seed(1)
> mat = matrix(rnorm(25), 5, 5)
> mat
[,1] [,2] [,3] [,4] [,5]
[1,] -0.6264538 -0.8204684 1.5117812 -0.04493361 0.91897737
[2,] 0.1836433 0.4874291 0.3898432 -0.01619026 0.78213630
[3,] -0.8356286 0.7383247
2010 Sep 03
2
Matrix to list
Dear all, suppose I have following matrix:
> mat <- matrix(rnorm(25), 5)
>
> mat
[,1] [,2] [,3] [,4] [,5]
[1,] 0.97056228 -1.3278509 -0.73511792 2.1650629 -0.4411997
[2,] 0.58613700 -0.2559899 -1.18334248 -1.4990907 1.8138846
[3,] -1.03333313 2.0227887 0.89622681 0.6483973 -1.5523283
[4,] 0.38968833 0.2490004 -0.02301061 -0.2705150
2011 Jan 25
1
NA printing
Hi.
I'm writing a print method for an object that includes a numeric matrix
for which
the lower diagonal elements are not meaningful. So I make the lower
diagonal of my matrix NA and print it.
But my co-author does not like NA there and wants a dash.
I have tried coercing the matrix to character, essentially by
M[is.na(M)] <- "-" but this interferes with the pleasing
column
2011 Jun 06
2
A Calculation on list object
Hello, I am into some calculation on a list object, therefore requesting the peers if there is any short cut way to so the same calculation.
Let say I have following list object:
> List <- vector('list', length = 3)
> set.seed(1)
> List[[1]] <- rnorm(5)
> List[[2]] <- rnorm(2)
> List[[3]] <- rnorm(7)
> List
[[1]]
[1] -0.6264538 0.1836433 -0.8356286
2009 Jul 01
5
convert tabular time series into a matrix format
Hi, thanks everyone for any help in advance.
I found myself dealing with a tabular time-series data formatted each row
like [ time stamp, ID, values]. I made a small examples:
X = data.frame(t=c(1,1,1,2,2,2,2,3,3,3,4,4,4,5,5),id =
2009 Jun 22
2
Help on creating a sequence of vectors
I want to create a number of vectors like :
vec1 <- rnorm(1)
vec2 <- rnorm(2)
vec3 <- rnorm(3)
and so on...........
Here I tried following :
for (i in 1:10) paste("vec", i, sep="") <- rnorm(i)
However obviously that is not working. Here vectors I need to be seperated
i.e I do not want to create a "list". How to modify above code?
--
View this
2004 Aug 13
1
How to use the whole dataset (including between events) in Cox model (time-varying covariates) ?
Hello,
coxph does not use any information that are in the dataset between event
times (or "death times") , since computation only occurs at event times.
For instance, removing observations when there is no event at that time in
the whole dataset does not change the results:
> set.seed(1)
> data <-
as.data.frame(cbind(start=c(1:5,1:5,1:4),stop=c(2:6,2:6,2:5),status=c(rep(
2005 Mar 01
6
Help : delete at random
Hello
I would like to delete some values at random in a data frame. Does
anyone know how I could do?
With best regards
Caroline
2010 Dec 23
2
R-way to doing this?
Dear friends, hope I could be able to explain my problem through following
example. Please consider this:
> set.seed(1)
> input <- rnorm(10)
> input
[1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078 -0.8204684
0.4874291 0.7383247 0.5757814 -0.3053884
> tag <- vector(length=10)
for(i in 1:10)
# if there is any ****error**** in evaluating
2009 Jun 11
2
How to force R to print 2 decimal places in column of a data.frame?
How to force R to print 2 decimal places in column of a data.frame? I tried to do so:
x = inp(format(rounf(inp$Tamanho, 2), nsmall = 2),)
where "INP" is data.frame and "Size" is the name of column. But has error:
Error in eval.with.vis(expr, envir, enclos) :
could not find function "inp"
Lesandro
Veja quais s?o os assuntos do momento no Yahoo! +Buscados
2005 Mar 04
11
R: simulation
hi all
a simple question
i want to run simulations in r. i however want the experiments to be
repeated at a later time with exactly the same numbers by other users.
can i set the random number seed for rnorm in some way?
e.g. is there some arguement that goes with rnorm?
please supply an example
regards
Allan
2011 Jul 16
2
(unclassified?) Help Question
Dear List,
I'd appreciate you guidance for obtaining the desired result shown
below, by combining tapply(x, g, mean) and g in the example.
Basically, I'm trying to create a vector whose values are based on the
result from tapply(x, g, mean) but that follow the pattern and length
given by the factor g. Of course I'm looking for a generic solution
(i.e, not something that just work
2006 Oct 02
1
CCF and ACF
Dear all,
given two numeric vectors x and y, the ACF(x) at lag k is
cor(x(t),x(t+k)) while the CCF(x,y) at lag k is cor(x(t),y(t-k)). See
below for a simple example.
> set.seed(1)
> x <- rnorm(10)
> y <- rnorm(10)
> x
[1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078 -0.8204684
0.4874291 0.7383247 0.5757814 -0.3053884
> y
[1] 1.51178117 0.38984324
2008 May 09
2
which.max2()
Hello,
which.max() only returns one index value, the one for the
maximum value. If I want the two index values for the two
largest values, is this a decent solution, or is there a
nicer/better R'ish way?
max2 <-function(v)
{
m=which.max(v)
v[m] = -v[m]
m2=which.max(v)
result=c(m, m2)
result
}
Seems to work ok.
Thanks,
Esmail
2011 Feb 02
0
How column names/row names are preserved in matrix calculation?
Can somebody tell me that, if I do some arithmetic calculation over 2
matrices then how the column names and row names are preserved? It seems
that, for multiplication, column names and row names of the 2nd matrix are
preserved and for additional, there seems not having any explicit rule:
> set.seed(1)
> dat1 <- matrix(rnorm(25), 5); colnames(dat1) = rownames(dat1) =
2010 Jun 26
4
integration of two normal density
Hello everyone,
I have a question about integration of two density function
Intuitively, I think the value after integration should be 1, but they are
not. Am I missing something here ?
> t=function(y){dnorm(y, mean=3)*dnorm(y/2, mean=1.5)}
> integrate(t, -Inf, Inf)
0.3568248 with absolute error < 4.9e-06
Also, is there any R function or package could do multivariate integration ?
2010 Jun 23
3
integrate dmvtnorm
Hello, everyone,
I have a question about integration of product of two densities.
Here is the sample code; however the mean of first density is a function of
another random variable, which is to be integrated.
##
f=function(x) {dmvnorm(c(0.6, 0.8), mean=c(0.75, 0.75/x))*dnorm(x, mean=0.6,
sd=0.15)}
integrate(f, lower=-Inf, upper=Inf)
## error message
Error in dmvnorm(c(0.6, 0.8), mean = c(0.75,
2011 Feb 07
2
questions about counting numbers
Hello R-helpers,
I have a question about counting numbers.
Here is a simple example.
a=c(2, 3, 3,4)
> table(a)
a
2 3 4
1 2 1
so, I can to create another variables that has the corresponding counting
numbers.
In this case, I want to have:
b=c(1,2,2,1)
Is there any way coding for this ?
Thanks for helps!
Carrie--
[[alternative HTML version deleted]]
2010 Jun 25
1
what "density" is plotting ?
Hi everyone,
I am confused regarding the function "density".
suppose that there is a sample x of 100 data points, and plot(density(x))
gives it's pdf ?
or it's more like histogram only ?
thanks for any answering
Carrie
[[alternative HTML version deleted]]
2011 May 08
1
questions about the output of "gee" and its summary
Dear R-helpers,
I am using the package "gee" to run a marginal model.
Here is the output.
In my simulated data, both x and z are time-varying, so I include their
interaction terms with time indicator (i.e. tind=0, if time 1, and 1 if time
2)
The data is simulated, so the true parameter of z both at time 1 and time 2
is 5, which is very close from the model output
for time 1, z =