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
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?
> m.control=c(1.45,9.40,9.96,4.2,1.86,0.2)
> m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09)
>
> t=function(m, a){(1-exp(-a*m))} #t function defined
>
> d=function(ts,
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
Hi Everyone,
I could use help developing a for loop. I have a dataset with tallies for
a number of species within 7 different size classes. I need to uncollate the
data into the rawest form (ie: each row a different individual) & retrain
the metadata associated with each row (Date, Recorder, Sit
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
I am having a hard time putting the below into a loop, where it pulls out ppt
from all he stations I have versus having to go through and hard code the data
to the specific stations. I tried
stnID <- stnid[which(duplicated(stnid)==FALSE)]
for(i in 1:length(stnID))
{
ppt[i] <- ppt[which(stnid==[i]
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
Subject: [R] for loop help
If you have:
Name Value
A 2
A 3
A 4
B 5
B 6
B7
In R how do you assign one value to the name:
A:9
B:18
--
View this message in context:
http://r.789695.n4.nabble.com/for-loop-help-tp2539621p2539621.html
Sent
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.
If you have:
Name Value
A 2
A 3
A 4
B 5
B 6
B7
In R how do you assign one value to the name:
A:9
B:18
--
View this message in context:
http://r.789695.n4.nabble.com/for-loop-help-tp2539621p2539621.html
Sent from the R help mailin
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
Hi Everyone,
I have a 2-dim data.matrix(e.g., table1) in which row1 specifies a range of
values. row2 - rown specify the number of times I want to replicate each
corresponding value in row1. I can do this with the following function:
rep(c(table1[1,]),c(table1[X,])) #where X would go from 2 -
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
Hi,
I have a dataset with three column like this
x1 x2 Count
1 0 523
1 0 23
0 0 2
0 1 45
0 0 3
1 1 433
I need to create a loop so that when c(x1,x2)=c(1,1), I can add the
corresponding Counts.When c(x1,x2)=c(1,0), can add the corresponding counts and
so on. Can anyone help me
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
11 April 2008 12:26 PM
To: r-help@r-project.org
Subject: [R] for loop help
Hi,
I am trying to find a solution in R for the following C++ code that
allows
one to skip ahead in the loop:
for (x = 0; x <= 13; x++){
x=12;
cout << "Hello World";
}
Note that "Hello World" was pri
Hi,
I am trying to find a solution in R for the following C++ code that allows
one to skip ahead in the loop:
for (x = 0; x <= 13; x++){
x=12;
cout << "Hello World";
}
Note that "Hello World" was printed only twice using this C++ loop. I
tried to do the same in R:
for(i in 1:13){
i=12
print
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,
Hi,
I have written the following code which works fine
step<-5
numSim<-15
N<-double(numSim)
A<-double(numSim)
F<-double(numSim)
M<-double(numSim)
genx<-double(numSim)
for (i in 1:numSim) {
N[i]<-20
PN<-(runif(N[i], 0, 1))
A[i]<-sum(ifelse(PN>0.2, 1, 0))
PF<- runif((A[i]*0.5
32 matches
Mail list logo