Hi,
I guess you need to change the parentheses from:
ts=sum(t(m.sham),pick.a[count])
#to
ts=sum(t(m.sham,pick.a[count]))
#similarly for tc:
for(count in 1:length(pick.a)){
ts=sum(t(m.sham,pick.a[count]))
tc=sum(t(m.control,pick.a[count]))
output[count,2] <- (ts-tc)/ts
}
A.K.
On Sunday, J
On 14-01-05 3:47 PM, Mathew Nagendran wrote:
I'm relatively new to R. I'm trying to for loop but I keep getting an error
message. Can anyone hint at what I am doing wrong please?
Nothing to do with the for loop. You have a call to your t function in
which you don't specify a value for the a
Hi,
You may try:
x <- 1:5
set.seed(49)
mat1 <- do.call(rbind,lapply(1:1000,function(y) sample(x,3)))
#or
mat2 <- matrix(0,ncol=3,nrow=1000)
set.seed(49)
for(i in seq_len(nrow(mat2))) mat2[i,] <- sample(x,3)
all.equal(mat1,mat2)
#[1] TRUE
#or
set.seed(49)
mat3 <- t(replicate(1000,sample(x,3))
Hello,
Please don't post datasets like this, it's unusable by us. Use dput().
?dput
dput(head(myData, 20)) # post the output of this.
Paste the output of that command in a post. It starts with 'structure'.
Don't worry if it looks awkward, it is, on the contrary, very usefull.
All we need to
Read your data using read.table with as.is=TRUE
then you could reformat the date column to make R understand that it is a
date, depending on your raw date format.
Thanks.
--
View this message in context:
http://r.789695.n4.nabble.com/For-loop-help-tp4636155p4636157.html
Sent from the R help maili
I'm not sure what you're doing... but here are some tips about the parts I
can understand.
1) you don't need to use "which" as much. This works fine:
stnID <- stnid[!duplicated(stnid)]
2) "which" works within a for loop
3) Do you realize that "stnID" is shorter after you removed duplicates
Hi Cassie,
I'm not sure exactly what you are trying to get: i assume that each
station will have a different ppt value for each year-month
combination, but it looks like you're trying to get one ppt value for
each station.
Steve
On Thu, Jul 28, 2011 at 1:30 AM, Wilson, Cassandra J wrote:
> I a
Hello,
So you want to sum Value by Name and assign to an object in your
workspace called Name ? (it's best to say specifically what the
desired output is when you post a question here).
Assuming your data are in a matrix or data.frame called foo, you could
use a for loop as follows...
for (nm i
Subject: Re: [R] for loop help
How do I create a hash table using R?
--
View this message in context:
http://r.789695.n4.nabble.com/for-loop-help-tp2539621p2539657.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org
Most likely.
If you care to be more specific, we might be able to give you a more specific
answer.
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of lord12
Sent: Wednesday, 15 September 2010 6:30 AM
To: r-help@r-project.org
Subject
How do I create a hash table using R?
--
View this message in context:
http://r.789695.n4.nabble.com/for-loop-help-tp2539621p2539657.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.
Thanks A LOT guys for your posts and replying despite the fact that it might
have been a bit hard to get my point (I apologise for the latter).
Josh's and Jim's examples worked perfectly. A loop was certainly not the
most elegant solution.
What I want to do (for those who asked) is re-generate
Hi:
It's not immediately clear what you have in mind, as others have noted, but
here are a couple of ideas that seem as though they may apply to your
problem, as dangerous as it is to play clairvoyant:
I'm using vectors instead of a matrix, but the first vector, val, contains
the values whereas t
try this:
> x <- matrix(sample(25,25), 5)
> x
[,1] [,2] [,3] [,4] [,5]
[1,] 12 24 143 20
[2,] 2175 15 17
[3,] 11 10 22 169
[4,]6 2541 23
[5,]2 198 13 18
> # save result in a list
> result <- lapply(2:nrow(x), function(.row){
I do not follow. Could you please provide a small reproducible example
of what "table1" might look like, and what you want as a result?
Surely you don't need a for loop.
alfredo wrote:
Hi Everyone,
I have a 2-dim data.matrix(e.g., table1) in which row1 specifies a range of
values. row2 - row
Hi A,
Here is a little example that I believe does what you want. I am not
quite sure how you want all the output in a new matrix, because as you
repeat each value is the first row varying numbers of times, you will
not have rows of equal length. Although perhaps your data is setup so
that you c
On 04/06/10 10:32, Petr PIKAL wrote:
One option:
t<- data.frame(x1=c(1,1,0,0,0,1), x2=c(0,0,0,1,0,1),
Count=c(523,23,2,45,3,433))
t.sum<- function(df, x1, x2) sum(df[df$x1==x1& df$x2==x2,]$Count)
[...]
If this is what Khan wants so
aggregate(t$Count, list(interaction(t$x1, t$x2)), sum)
Gro
Hi
r-help-boun...@r-project.org napsal dne 03.06.2010 18:18:33:
> One option:
>
> t <- data.frame(x1=c(1,1,0,0,0,1), x2=c(0,0,0,1,0,1),
> Count=c(523,23,2,45,3,433))
> t.sum <- function(df, x1, x2) sum(df[df$x1==x1 & df$x2==x2,]$Count)
> t.sum(t, 1, 0)
> # [1] 546
> t.sum(t, 0, 0)
> # [1] 5
If
Hi Geeti,
If d is your data.frame, the following is an option:
as.data.frame.table(with(d, tapply(Count, list(x1, x2), sum)))
HTH,
Jorge
On Thu, Jun 3, 2010 at 11:18 AM, Geeti Khan <> wrote:
> Hi,
> I have a dataset with three column like this
> x1 x2 Count
> 1 0 523
> 1 0 23
> 0 0 2
> 0 1
One option:
t <- data.frame(x1=c(1,1,0,0,0,1), x2=c(0,0,0,1,0,1),
Count=c(523,23,2,45,3,433))
t.sum <- function(df, x1, x2) sum(df[df$x1==x1 & df$x2==x2,]$Count)
t.sum(t, 1, 0)
# [1] 546
t.sum(t, 0, 0)
# [1] 5
Hope this helps a little.
Allan
On 03/06/10 16:18, Geeti Khan wrote:
Hi,
I have a
mailto:[EMAIL PROTECTED] On Behalf Of
> [EMAIL PROTECTED]
> Sent: Thursday, April 10, 2008 9:38 PM
> To: [EMAIL PROTECTED]; r-help@r-project.org
> Subject: Re: [R] for loop help
>
> > ?`break`
> > ?`next`
>
> > for(i in 1:13) {
> if(i < 13) next
> pri
On 11.04.2008, at 05:38, <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]> wrote:
>> ?`break`
>> ?`next`
>>
>
>
>> for(i in 1:13) {
>>
> if(i < 13) next
> print("Hello!\n")
> }
> [1] "Hello!\n"
>
>>
>>
>
> I am trying to find a solution in R for the following C++ code that
> allows
> one to s
> ?`break`
> ?`next`
> for(i in 1:13) {
if(i < 13) next
print("Hello!\n")
}
[1] "Hello!\n"
>
Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary): +61 7 3826 7304
Mobile:
Is this what you want?
> numSim <- 15
>
> genx<-double(numSim)
> N <- rep(20, numSim)
> A <- F <- M <- numeric(numSim)
>
> result <- lapply(1:5, function(.x){
+ for (i in 1:numSim) {
+ PN<-(runif(N[i], 0, 1))
+ A[i]<-sum(ifelse(PN>0.2, 1, 0))
+ PF<- runif((A[i]*0.5), 0,
24 matches
Mail list logo