Dear Fazal
I think part of your problem can be addressed with merge
go
?merge
at the R prompt
On 01/05/2015 21:05, Hadi Fazal wrote:
Hi everyone,
I am a real beginner to R and have probably a very naive issue. I've a small
data frame with three columns: Unique Sample ID, Gene 1 and Gene 2 (the
Fazal,
I am not sure what you want, but I have guessed. I have tried to provide a
straight forward simplistic solution.
If you examine the intermediate results, I think what is being done will be
clear.
Mark
Michael Dewey’s suggestion to look at merge is excellent. You may also need to
look
questions in R-help see
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
welcome to R-help
John Kane
Kingston ON Canada
-Original Message-
From: fazal.h...@curie.fr
Sent: Fri, 1 May 2015 20:05:22 +
To: r-help@r-project.org
Subject: [R] Help
Hi everyone,
I am a real beginner to R and have probably a very naive issue. I've a small
data frame with three columns: Unique Sample ID, Gene 1 and Gene 2 (the columns
on Gene1 and Gene2 are empty). I have two separate tables for the genes which
contain the Unique Subject ID in one column
Hello,
Although the example below doesn't necessary make any sense from a
statistical perspective, it is just a close enough example to hopefully get
your help upon.
For my purpose, I'm particularly interested to know if there is a way to
replace the results from the vapply() function below by a
in context:
http://r.789695.n4.nabble.com/Help-with-R-loop-for-URL-download-from-FRED-to-create-US-time-series-tp4669209.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r
(url))
}
tmp
thanks for your help
--
View this message in context:
http://r.789695.n4.nabble.com/Help-with-R-loop-for-URL-download-from-FRED-to-create-US-time-series-tp4669209.html
Sent from the R help mailing list archive at Nabble.com.
__
R
I want my for loop to test for the presence of a term in a vector and return
a value to a new vector. I'm not writing it correctly though. Here's what I
have...
testfor = letters[1:5]
x = c(a, b, e, f, g)
result = rep(NA, length(testfor))
for (i in testfor){
+ v = any(x == testfor[i])
+
On Nov 10, 2012, at 2:07 PM, scoyoc wrote:
I want my for loop to test for the presence of a term in a vector and return
a value to a new vector. I'm not writing it correctly though. Here's what I
have...
testfor = letters[1:5]
x = c(a, b, e, f, g)
result = rep(NA, length(testfor))
for
-Original Message-
From: arun [mailto:smartpink...@yahoo.com]
Sent: Tuesday, October 30, 2012 1:57 PM
To: Meredith, Christy S -FS
Cc: R help; William Dunlap
Subject: Re: [R] help with for loop: new column giving count of observation for
each SITEID
HI,
You can also use this:res-do.call(rbind
Hello,
I think this is easy, but I can't seem to find a good way to do this in the R
help. I have a list of sites, with multiple years of data for each site id. I
want to create a new column that gives a number describing whether it is the
1st year (1 ) the data was collected for the site, the
To: r-help@R-project.org
Subject: [R] help with for loop: new column giving count of observation for
each SITEID
Hello,
I think this is easy, but I can't seem to find a good way to do this in the R
help. I have a list
of sites, with multiple years of data for each site id. I want to create
, Christy S -FS; r-help@R-project.org
Subject: RE: [R] help with for loop: new column giving count of observation for
each SITEID
Is this what you want?
withinGroupIndex - function(group, ...) ave(integer(length(group)), group,
..., FUN=seq_along)
site - c(A,A,C,D,C,A,B)
data.frame(site
: RE: [R] help with for loop: new column giving count of observation
for each
SITEID
Not quite,
I need it like this, a new number for each ordered year in the sequence
within each site,
regardless of what the years are, and to retain the RchID column.
RchID siteyearindex
1
2
9 C 20043
Thanks so much for you help!
-Original Message-
From: William Dunlap [mailto:wdun...@tibco.com]
Sent: Tuesday, October 30, 2012 1:07 PM
To: Meredith, Christy S -FS; r-help@R-project.org
Subject: RE: [R] help with for loop: new column giving count
csmered...@fs.fed.us
Cc: r-help@r-project.org r-help@r-project.org
Sent: Tuesday, October 30, 2012 3:43 PM
Subject: Re: [R] help with for loop: new column giving count of observation for
each SITEID
Your data was, in R-readable format (from dput())
d - data.frame(
RchID = 1:9,
site
-FS csmered...@fs.fed.us
Cc: r-help@r-project.org r-help@r-project.org
Sent: Tuesday, October 30, 2012 3:43 PM
Subject: Re: [R] help with for loop: new column giving count of observation
for each SITEID
Your data was, in R-readable format (from dput())
d - data.frame(
RchID = 1:9
I'm not sure I follow exactly what group of regression models you want to
create, but a good first step might be to use reshape so that each party's
vote share goes on a different row and the vote shares are all in the same
column. Then you can use plyr grouping on tipo and party to make your
Peter:
many thanks for your help. This is basically what I wanted to do and in
a much more elegant way.
On Mon, Mar 19, 2012 at 03:13:40AM -0700, Peter Meilstrup wrote:
I'm not sure I follow exactly what group of regression models you want to
create, but a good first step might be to use
Hi,
I have a dataframe basically like this:
head(asturias.gen2011[,c(1,4,9:14)])
municipio total upyd psoeppiu factipo
440 Allande 2031 1.44 31.10 39.75 4.01 21.62 1000-1
443Aller 12582 1.37 33.30 37.09 15.53 10.35
-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of MacQueen, Don
Sent: Friday, September 16, 2011 6:58 PM
To: Luke Miller; beaulieu.j...@epamail.epa.gov
Cc: r-help@r-project.org
Subject: Re: [R] Help writing basic loop
Just a minor aside; I would have done
my.slopes
Hello,
I would like to write a loop to 1) run 100 linear regressions, and 2)
compile the slopes of all regression into one vector. Sample input data
are:
y1-rnorm(100, mean=0.01, sd=0.001)
y2-rnorm(100, mean=0.1, sd=0.01)
x-(c(10,400))
#I have gotten this far with the loop
for (i in 1:100)
Create an output vector to hold your slopes before starting the loop, then
use your index i to place each new slope in the appropriate position in your
vector.
y1-rnorm(100, mean=0.01, sd=0.001)
y2-rnorm(100, mean=0.1, sd=0.01)
x-(c(10,400))
my.slopes = vector(numeric,100) # initialize a
You can also do the regressions in parallel as follows:
x = -25:25
y = 0.05*x^2 + 2* x - 4
y1 = y + rcauchy(51)
y2 = y + rcauchy(51)^2
y3 = y/10 - 5 + rnorm(51)
Y = cbind(y, y1, y2, y3)
m = lm(Y~x)
print(coef(m))
Hope this helps,
Michael
On Fri, Sep 16, 2011 at 3:37 PM, Luke Miller
Just a minor aside; I would have done
my.slopes - numeric(100)
Note that:
class(numeric(5))
[1] numeric
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 9/16/11 12:37 PM, Luke Miller mille...@gmail.com wrote:
Hi,
I think you can do this without a loop (well, replicate() is based on
sapply()):
prob-numeric(1000)
task1 - replicate(1000,runif(1, min=0.8, max= 0.9))
task2 - replicate(1000,runif(1, min=0.75, max= 0.85))
task3 - replicate(1000,runif(1, min=0.81, max= 0.89))
prob - task1*task2*task3
It
Hi:
Let's assume the lengths of each vector are the same so that they can be
multiplied. Here's the timing on my machine:
system.time(replicate(1000, { prob-numeric(1000)
+
+ for (n in 1:1000) {
+ task1 - runif(1, min=0.8, max= 0.9)
+ task2 - runif(1, min=0.75, max= 0.85)
+ task3 - runif(1,
Well, I was quite blind not to change 1 to 1000 in runif() and use
replicate()!!
It gets even faster if you create prob first.
Ivan
Le 4/11/2011 10:53, Dennis Murphy a écrit :
Hi:
Let's assume the lengths of each vector are the same so that they can
be multiplied. Here's the timing on my
The loop is correct, you just need to make sure that your result is computed
and stored as the n-th element that is returned by the loop. Pick up any
manual of R, and looping will be explained there. Also, I would recommend
that you draw a random number for every iteration of the loop. Defining
On Thu, Jan 27, 2011 at 05:30:15PM +0100, Petr Savicky wrote:
On Thu, Jan 27, 2011 at 11:30:37AM +0100, Serena Corezzola wrote:
Hello everybody!
I?m trying to define the optimal number of surveys to detect the highest
number of species within a monitoring season/session.
[...]
Hello Petr.
First of all, thank you for your help!
If i understand you correctly, your real table U has 32 rows and you want
to consider all subsets of at most 10 rows.
Sorry, I wasnt clear: I have more datasets to analyse, some of them of just
10 samples, and others of 32.
So:
Hello everybody!
Im trying to define the optimal number of surveys to detect the highest
number of species within a monitoring season/session.
To do this I want to run all the possible combinations between a set of
samples and to calculate the total number of species for each combination of
On Thu, Jan 27, 2011 at 11:30:37AM +0100, Serena Corezzola wrote:
Hello everybody!
I?m trying to define the optimal number of surveys to detect the highest
number of species within a monitoring season/session.
To do this I want to run all the possible combinations between a set of
] On
Behalf Of jim holtman
Sent: Friday, January 01, 2010 5:25 PM
To: Rafael Moral
Cc: r-help
Subject: Re: [R] help with for loop
Look at your function; it is returning exactly what you are asking for:
x.dif - c(diff(my.vec), diff(my.vec, lag=i)) # the first and last values
You probably want
Dear useRs,
I want to write a function that generates all the possible combinations of
diff().
Example:
If my vector has length 5, I need the diff() until lag=4 -
c(diff(my.vec), diff(my.vec, lag=2), diff(my.vec, lag=3), diff(my.vec, lag=4))
If it has length 4, I need until lag=3 -
Look at your function; it is returning exactly what you are asking for:
x.dif - c(diff(my.vec), diff(my.vec, lag=i)) # the first and last values
You probably want something like this:
dif - function(my.vec) {
x.diff - diff(my.vec)
for(i in 2:(length(my.vec)-1)) {
x.dif - c(x.diff, diff(my.vec,
diff.zoo in the zoo package can take a vector of lags:
library(zoo)
z - zoo(seq(10)^2)
diff(z, 1:4)
There are three vignettes (pdf documents) that come with zoo that have
more info on the package.
On Fri, Jan 1, 2010 at 8:16 PM, Rafael Moral
rafa_moral2...@yahoo.com.br wrote:
Dear useRs,
I
Hi there
I have two tables, with longitudinal and latitudinal coordinates. what I
want is a cross table between each coordinate, to find the distance between
each building and different landmarks
I currently have this nested loop which is fine for when i have 10 stores of
interest, against 200
From an old post by Gabor
http://tolstoy.newcastle.edu.au/R/help/04/01/0147.html
apply
(outer
(landmark_c,t(store_c),-),c(1,4),function(x)sqrt(sum(diag(x*x
On 7 Dec 2009, at 10:58PM, dolar wrote:
Hi there
I have two tables, with longitudinal and latitudinal coordinates.
what I
Hi,
I’d like to ask for some help in writing a loop. My situation is the following:
I have a matrix (matrix.A) containing 3 columns and 100 rows. The columns
represent parameter estimates a, b, and c. The rows contain different values
for these parameter estimates. Each row is unique.
I
-project.org [r-help-boun...@r-project.org] On Behalf Of
Jessica Schedlbauer [jsche...@fiu.edu]
Sent: November 25, 2009 10:43 AM
To: r-help@r-project.org
Subject: [R] help writing for loop
Hi,
I’d like to ask for some help in writing a loop. My situation is the following:
I have a matrix (matrix.A
Dear Users,
I follow Andreas idea to simulate an ar(1) model with a new kind of innovation
process.
The new argument rand.gen, for the arima.sim function, I'm trying to generate
as:
tGarchGen - function(a, b, c) {
# must return a vector of random deviates (eta(t))
for (t in 1:100){
I have a code:
*a = c(4,5,1,7,8,12,39)
b = c(3,7,8,4,7,25,78)
d =a-b
for(i in 1:length(d)){
if(d[i]0){x = list(d[i])
print(x)}
else{y = list(d[i])
print(y)}}
the results are:
[[1]]
[1] 1
[[1]]
[1] -2
[[1]]
[1] -7
[[1]]
[1] 3
[[1]]
[1] 1
[[1]]
[1] -13
[[1]]
[1] -39
which will tell me what
(d 0)
Erik
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Edward Chen
Sent: Monday, September 14, 2009 1:50 PM
To: r-help@r-project.org
Subject: [R] Help with for loop
I have a code:
*a = c(4,5,1,7,8,12,39)
b = c(3,7,8,4,7,25,78
Hi Edward,
Here is a suggestion:
a = c(4,5,1,7,8,12,39)
b = c(3,7,8,4,7,25,78)
d - a-b
d[which(d0)]
# [1] 1 3 1
HTH,
Jorge
On Mon, Sep 14, 2009 at 2:50 PM, Edward Chen edche...@gmail.com wrote:
I have a code:
*a = c(4,5,1,7,8,12,39)
b = c(3,7,8,4,7,25,78)
d =a-b
for(i in 1:length(d)){
On Sep 14, 2009, at 3:02 PM, Jorge Ivan Velez wrote:
Hi Edward,
Here is a suggestion:
a = c(4,5,1,7,8,12,39)
b = c(3,7,8,4,7,25,78)
d - a-b
d[which(d0)]
# [1] 1 3 1
#Or even:
d - (a-b)[which((a-b)0)]
d
#[1] 1 3 1
HTH,
Jorge
On Mon, Sep 14, 2009 at 2:50 PM, Edward Chen
Or:
(a - b)[b a]
On Mon, Sep 14, 2009 at 4:16 PM, David Winsemius dwinsem...@comcast.netwrote:
On Sep 14, 2009, at 3:02 PM, Jorge Ivan Velez wrote:
Hi Edward,
Here is a suggestion:
a = c(4,5,1,7,8,12,39)
b = c(3,7,8,4,7,25,78)
d - a-b
d[which(d0)]
# [1] 1 3 1
#Or even:
d -
-371-4717
From: www...@gmail.com
Date: Mon, 14 Sep 2009 16:35:23 -0300
Subject: Re: [R] Help with for loop
To: dwinsem...@comcast.net
CC: jorgeivanve...@gmail.com; r-help@r-project.org; edche...@gmail.com
Or:
(a - b)[b a]
On Mon, Sep 14, 2009 at 4:16 PM, David Winsemius dwinsem...@comcast.net
] Help with for loop
To: dwinsem...@comcast.net
CC: jorgeivanve...@gmail.com; r-help@r-project.org; edche...@gmail.com
Or:
(a - b)[b a]
On Mon, Sep 14, 2009 at 4:16 PM, David Winsemius
dwinsem...@comcast.netwrote:
On Sep 14, 2009, at 3:02 PM, Jorge Ivan Velez wrote:
Hi Edward,
Here
On Sep 14, 2009, at 5:14 PM, edche...@gmail.com edche...@gmail.com
wrote:
thank you all for your help. I do know how to use which() but my
problem is that I am writing a function in which this is just part
of it. After seeing the (a-b)[ba], it gives the wrong index number
for which is
example code:
P = function(whichday,columns){
y = which(pvalue[,whichday]Pvaluetest, arr.ind=TRUE)
dayarb = raw_urine[y,day1_ind]
daystand = raw_urine[y,columns]
meandayxx = geometricmeanRow(dayarb)
meandayyy = geometricmeanRow(daystand)
diff = meandayyy - meandayxx
for(i in 1:nrow(diff)){
Hi,
On Sep 11, 2009, at 6:35 PM, Edward Chen wrote:
example code:
P = function(whichday,columns){
y = which(pvalue[,whichday]Pvaluetest, arr.ind=TRUE)
dayarb = raw_urine[y,day1_ind]
daystand = raw_urine[y,columns]
meandayxx = geometricmeanRow(dayarb)
meandayyy = geometricmeanRow(daystand)
diff
Hi R-helpers.
#I start with the reproducible example:
firm-c(rep(1,10),rep(2,10),rep(3,10),rep(4,10),rep(5,10))
year-c(rep(1998:2007,5))
industry-c(rep(1,20),rep(5,10),rep(7,10),rep(9,10))
X1-rnorm(50)
X2-rnorm(50,mean=0.5,sd=0.1)
Y-rnorm(50,mean=0,sd=0.5)
data-data.frame(firm,
Your data has 2 points per regression for each year in industry 1 and
only one point per regression for the other industries so one would
expect many NAs:
table(data[c(industry, year)])
year
industry 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007
1222222
Dear List,
I have a wrapper function that draws a graph that I'd like to use in a
vector-like manner. The for-loop version I currently use is below.
library(ggplot2)
data(economics)
h - 600
w - 800
#--
draw_metric_by_date - function(
Hi,
Here's one approach that I find perhaps more elegant than sweeping
through the columns by their index,
library(ggplot2)
data(economics)
str(economics)
# library(reshape)
d - melt(economics, id=date)
foo - function(var=pop, d, smooth=FALSE, ... ) {
p - qplot( data=subset(d,
Dear List,
Hadley offered the following solution:
library(plyr)
l_ply(2:6, draw_metric_by_date, df = economics, smooth = TRUE, BASEPATH =
basepath)
Many thanks,
Avram
On Wednesday, April 29, 2009, at 12:59PM, Avram Aelony aav...@mac.com wrote:
Dear List,
I have a wrapper function
You are right to be dissatisfied with your code.
I suspect you will get more response if you say
what the code is supposed to do, and give a
smaller example of what the answer should be.
Patrick Burns
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and A Guide
HI
the code is suppose to generate a random value selected uniformly as a time
interval in seconds (that's the dT) from the range given fromdtmin-969
dtmax-9884. Once that value is selected the program will generate the
interval (ts1, ts2, and so on. for each sampling without getting out of
HI:
I need ideas on how to make this code shorter (maybe with a second loop?).
The code as it is works, but in this case I only have 14 samples, but it
will become insane with more, so I need a way to make it more automatic. The
problem is that the output from ts1, ts2, and so on is a vector with
://www.nabble.com/R-help-on-for-loop-tp18098661p18098661.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R
to scan through till the end of the row.
can i use like this.
for ( i in 1:row(map)
{
}
Kindly clarify me
Cheers
Ramya
--
View this message in context:
http://www.nabble.com/R-help-on-for-loop-tp18098661p18098661.html
Sent from the R help mailing list archive at Nabble.com
I am having trouble getting a loop to work for the following problem. Any
help would be much appreciated. Thanks.
I need to find the slope and intercept from the linear regression of Drug
Level on Day by Participant. There are a total of 37 Participants. I need to
store the Participant, Label,
: Sunday, December 02, 2007 11:33 PM
Subject: [R] Help with a Loop
I am having trouble getting a loop to work for the following
problem. Any
help would be much appreciated. Thanks.
I need to find the slope and intercept from the linear regression of
Drug
Level on Day by Participant
There are three ways listed here:
https://stat.ethz.ch/pipermail/r-help/2007-May/132866.html
On Dec 2, 2007 5:33 PM, stathelp [EMAIL PROTECTED] wrote:
I am having trouble getting a loop to work for the following problem. Any
help would be much appreciated. Thanks.
I need to find the slope
65 matches
Mail list logo