Re: [R] Multilevel model in lme4 and nlme

2011-09-13 Thread jonas garcia
Hi Ben, thanks for your reply.

Your suggestion does not work indeed:



lme(y ~ x, random=list(~1|a:b, ~1|b:c), data=mydata)

Error in getGroups.data.frame(dataMix, groups) :

  Invalid formula for groups



Here is a reproducible example of my data:



set.seed(123)

library(lme4)

library(nlme)



y- rnorm(30)

x-rnorm(30)

a- factor(sort(rep(c(alpha, beta, charlie), 10)))

b- factor(rep(c(rho, epsilon, lambda), 10))

c- factor(c(sort(rep(1:2, 5)), sort(rep(3:4, 5)), sort(rep(5:6, 5

mydata- data.frame(y,x,a,b,c)





mod1- lmer(y ~ x + (1|a:b) + (1|b:c), data=mydata)



mod2.lme- lme(y ~ x, random=list(a=~1, b=~1, c=~1), data=mydata)

mod2.lmer- lmer(y ~ x + (1|a) + (1|a:b) + (1|a:b:c), data=mydata)



My objective is to specify mod1 using function lme.

Anyone knows how to do it?

Thanks



J




On Mon, Sep 12, 2011 at 9:43 PM, Ben Bolker bbol...@gmail.com wrote:

 jonas garcia garcia.jonas80 at googlemail.com writes:

  I am trying to fit some mixed models using packages lme4 and nlme.
 
  I did the model selection using lmer but I suspect that I may have some
  autocorrelation going on in my data so I would like to have a look using
 the
  handy correlation structures available in nlme.
 
  The problem is that I cannot translate my lmer model to lme:
 
  mod1- lmer(y~x + (1|a:b) + (1|b:c), data=mydata)
 
  a, b and c are factors with c nested in b and b nested in a
 
  The best I can do with lme is:
 
  mod2- lme(y~x, random=list(a=~1, b=~1, c=~1), data=mydata)
 
  which is the same as:
 
  lmer(y~x + (1|a) + (1|a:b) + (1|a:b:c), data=mydata)
 
  I am not at all interested in random effects (1|a) and (1|a:b:c) as they
 are
  not significant. I just need two random intercepts as specified in mod1.
 How
  can I translate mod1 into lme language?
 
  Any help on this would be much appreciated.

  This would probably be better on the r-sig-mixed-models list.

  Does random=list(~1|a:b,~1|b:c) work?

  I would be a little bit careful throwing out ~1|a (non-significance
 is not necessarily sufficient reason to discard a term from the model --
 it depends a lot on your procedure), and with the interpretation of
 your nesting.  If b is only explicitly and not implicitly nested in a
 (i.e. if there a levels of 'b' that occur in more than one level of 'a',
 for example if a corresponded to families, b corresponded to individuals,
 and you labeled individuals 1..N_b_i in each family) then I'm not
 sure how you would actually interpret b:c, as it would be crossed
 rather than nested.  But assuming that your model specification in
 lmer is correct and sensible, I think my suggestion above should (?)
 work to get the equivalent in lme.
 
  Jonas

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Multilevel model in lme4 and nlme

2011-09-12 Thread jonas garcia
Dear list,



I am trying to fit some mixed models using packages lme4 and nlme.

I did the model selection using lmer but I suspect that I may have some
autocorrelation going on in my data so I would like to have a look using the
handy correlation structures available in nlme.



The problem is that I cannot translate my lmer model to lme:


mod1- lmer(y~x + (1|a:b) + (1|b:c), data=mydata)


a, b and c are factors with c nested in b and b nested in a


The best I can do with lme is:



mod2- lme(y~x, random=list(a=~1, b=~1, c=~1), data=mydata)



which is the same as:



lmer(y~x + (1|a) + (1|a:b) + (1|a:b:c), data=mydata)



I am not at all interested in random effects (1|a) and (1|a:b:c) as they are
not significant. I just need two random intercepts as specified in mod1. How
can I translate mod1 into lme language?



Any help on this would be much appreciated.



Jonas

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] calculate area between intersecting polygons

2010-10-27 Thread jonas garcia
Many thanks for your help!
Thanks to you guys I manage to solve my problem in an efficient way

All the best

J

On Tue, Oct 26, 2010 at 11:04 PM, Remko Duursma remkoduur...@gmail.comwrote:


 I don't know why I forgot that you can do this as well :

 area.poly(intersect(p1,p2))

 ... a bit more straightforward.


 greetings,
 Remko
 --
 View this message in context:
 http://r.789695.n4.nabble.com/calculate-area-between-intersecting-polygons-tp3012980p3014581.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-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] calculate area between intersecting polygons

2010-10-26 Thread jonas garcia
Thanks for your reply,

My main issue is that I don't have any equations to generate the data, just
a bunch of points, each corresponding to a polygon.

I was looking in package sp and there is a function to calculate areas (
areapl()), but not for intersecting polygons. Is there any other package
that does this?
Thanks
On Tue, Oct 26, 2010 at 3:38 AM, Remko Duursma remkoduur...@gmail.comwrote:


 Dear Jonas,

 if you can write the difference in y-values between your polygons as a
 function, you can use
 integrate() to get the area between the polygons.

 It sounds like perhaps your x-values will not match between the polygons
 because they come from different sources, so you probably have to do some
 interpolating (with ?approx).


 hope that helps,
 Remko
 --
 View this message in context:
 http://r.789695.n4.nabble.com/calculate-area-between-intersecting-polygons-tp3012980p3013059.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-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] calculate area between intersecting polygons

2010-10-25 Thread jonas garcia
Dear list:



I am trying to calculate the intersection area between two irregular
polygons (see example data below).



set.seed(1234)

theta - seq(0, 2 * pi, length=(100))

poly1-  cbind(c(0 + 1 * cos(theta) + rnorm(100, sd=0.1)), c(0 + 2 *
sin(theta)))

poly2-  cbind(c(0 + 2 * cos(theta) ), c(-1 + 1.5 * sin(theta)+ rnorm(100,
sd=0.1)))



plot(x, y, type = n, , xlim=c(-5,5), ylim=c(-5,5))

polygon(poly1)

polygon(poly2)





My data correspond to geographical positions, therefore I cannot generate it
using equations as I did in the example.

Are there any straightforward algorithm to calculate the intersection area
between polygons poly1 and poly2?



Thank you so much in advance



Jonas

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] help identifying clusters

2010-10-20 Thread jonas garcia
Dear list:

I have a dataset of geographical data that looks like this example data:

dat- data.frame( lon = c(rnorm(1000, mean=-10), rnorm(1000, mean=10),
rnorm(1000, mean=5)),
  lat = c(rnorm(1000, mean=40), rnorm(1000, mean=30), rnorm(1000, mean=0)))

plot(dat$lon, dat$lat)

My positions are clearly clustered (in this example there are 3 clusters).
Is there any R algorithm that
allows me to identify the three groups of points and allocate to each pair
the respective cluster?

Many thanks in advance

Jonas

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] End of line marker?

2010-03-05 Thread jonas garcia
Jim, Duncan and David,

Thanks to you guys I manage to solve the problem and I have learnt a lot.
Best regards

J

On Fri, Mar 5, 2010 at 4:55 AM, Duncan Murdoch murd...@stats.uwo.ca wrote:

 On 04/03/2010 11:40 PM, David Winsemius wrote:

 On Mar 4, 2010, at 10:58 PM, Duncan Murdoch wrote:

 On 04/03/2010 10:32 PM, David Winsemius wrote:

 On Mar 4, 2010, at 9:47 PM, jonas garcia wrote:

 When I opened the file with a hex-editor, the problematic  character
  turned out to be “1a”
 I am attaching a sample DAT file with 3 lines (the second line is   the
 one with the undesirable character).

 The furthest I could get was through readBin:

 tmp- readBin(new.dat, what = raw, n=1)

  [1] 30 32 3a 33 35 3a 33 32 2c 20 34 34 30 33 2c 20 33 37 2e 31  31
  34 2c 2d 32 30 2e 38 33 36 2c 31
 [33] 35 35 2e 39 2c 30 30 2e 37 36 2c 31 31 35 36 0d 0a 30 32 3a  33
  35 3a 33 35 2c 20 34 34 33 32 2c
 [65] 20 33 37 2e 31 31 34 2c 2d 32 30 2e 38 33 36 2c 31 35 35 2e  38
  2c 1a 30 2e 38 31 2c 31 31 35 37
 [97] 0d 0a 30 32 3a 33 35 3a 33 39 2c 20 34 34 36 37 2c 20 33 37  2e
  31 31 34 2c 2d 32 30 2e 38 33 36
 [129] 2c 31 35 35 2e 38 2c 30 30 2e 38 31 2c 31 31 35 38


 tmp[87]

 [1] 1a

 I got a different interpretation of that character when I let R  look
  at it. And I cannot figure out why \032 should be causing  problems??? :

 Hex 1a and octal 032 both correspond to Ctrl-Z, which is the MSDOS  EOF
 marker.  I forget whether R's text reading routines pay  attention to that,
 or whether it's the C runtime, but it makes sense  that it would cause
 problems on Windows.

 Duncan Murdoch


 Thanks. I was interpreting \032 as decimal, so couldn't figure out why  it
 should equal 0x1A. You've explained the basis (or base) of my  confusion.


 By the way, here's one way to remove the bad char.  Read it using readBin
 as above, then

 tmp - tmp[tmp != 0x1a]

 to remove the bad chars, or

 tmp[tmp == 0x1a] - charToRaw( )

 to replace them with spaces.  Then write the tmp vector out to a file with
 writeBin.

 Duncan Murdoch


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] End of line marker?

2010-03-04 Thread jonas garcia
Thank you so much for your reply.



I can identify the characters very easily in a couple of files. The reason I
am worried is that I have thousands of files to read in. The files were
produced in a very old MS-DOS software that records information on
oceanographic data and geographic position during a survey.



My main goal is read all these files into R for further analysis. Most of
the files are cleared of these EOL markers but some are not. I only noticed
the problem by chance when I was looking and comparing one of them. I wonder
if I can solve this problem using R, without having to go for text editors
separately.



Help on this would be much appreciated.

Thanks again



J


On 3/4/10, David Winsemius dwinsem...@comcast.net wrote:


 On Mar 3, 2010, at 2:22 PM, jonas garcia wrote:

 Dear R users,

 I am trying to read a huge file in R. For some reason, only a part of the
 file is read. When I further investigated, I found that in one of my
 non-numeric columns, there is one odd character responsible for this,
 which
 I reproduce bellow:
 In case you cannot see it, it looks like a right arrow, but it is not the
 one you get from microsoft word in menu insert symbol.

 I think my dat file is broken and that funny character is an EOL marker
 that
 makes R not read the rest of the file. I am sure the character is there by
 chance but I fear that it might be present in some other big files I have
 to
 work with as well. So, is there any clever way to remove this inconvenient
 character in R avoiding having to edit the file in notepad and remove it
 manually?

 Code I am using:

 read.csv(new3.dat, header=F)

 Warning message:
 In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on 'new3.dat'


 I think you should identify the offending line by using the count.fields
 function and fix it with an editor.


 --
 David


 I am working with R 2.10.1 in windows XP.

 Thanks in advance

 Jonas

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] End of line marker?

2010-03-04 Thread jonas garcia
When I opened the file with a hex-editor, the problematic character turned
out to be “1a”

 I am attaching a sample DAT file with 3 lines (the second line is the one
with the undesirable character).



The furthest I could get was through readBin:



 tmp- readBin(new.dat, what = raw, n=1)

  [1] 30 32 3a 33 35 3a 33 32 2c 20 34 34 30 33 2c 20 33 37 2e 31 31 34 2c
2d 32 30 2e 38 33 36 2c 31

 [33] 35 35 2e 39 2c 30 30 2e 37 36 2c 31 31 35 36 0d 0a 30 32 3a 33 35 3a
33 35 2c 20 34 34 33 32 2c

 [65] 20 33 37 2e 31 31 34 2c 2d 32 30 2e 38 33 36 2c 31 35 35 2e 38 2c 1a
30 2e 38 31 2c 31 31 35 37

 [97] 0d 0a 30 32 3a 33 35 3a 33 39 2c 20 34 34 36 37 2c 20 33 37 2e 31 31
34 2c 2d 32 30 2e 38 33 36

[129] 2c 31 35 35 2e 38 2c 30 30 2e 38 31 2c 31 31 35 38





 tmp[87]

[1] 1a



The idea now is as Jim suggested, replace “1a” by (for example) “20” in the
raw format and write the file back with

writeBin(tmp, new2.dat)



Can I use gsub? How can I perform this operation without messing around with
the raw format?



Thanks

J




On Thu, Mar 4, 2010 at 8:35 PM, jim holtman jholt...@gmail.com wrote:

 Have you considered reading the file in a binary/raw, finding the
 offending character and replacing it with a blank (or whatever and
 then writing the file back out).  You can then probably process it
 using read.table.;

 On Thu, Mar 4, 2010 at 12:50 PM, jonas garcia
 garcia.jona...@googlemail.com wrote:
  Thank you so much for your reply.
 
 
 
  I can identify the characters very easily in a couple of files. The
 reason I
  am worried is that I have thousands of files to read in. The files were
  produced in a very old MS-DOS software that records information on
  oceanographic data and geographic position during a survey.
 
 
 
  My main goal is read all these files into R for further analysis. Most of
  the files are cleared of these EOL markers but some are not. I only
 noticed
  the problem by chance when I was looking and comparing one of them. I
 wonder
  if I can solve this problem using R, without having to go for text
 editors
  separately.
 
 
 
  Help on this would be much appreciated.
 
  Thanks again
 
 
 
  J
 
 
  On 3/4/10, David Winsemius dwinsem...@comcast.net wrote:
 
 
  On Mar 3, 2010, at 2:22 PM, jonas garcia wrote:
 
  Dear R users,
 
  I am trying to read a huge file in R. For some reason, only a part of
 the
  file is read. When I further investigated, I found that in one of my
  non-numeric columns, there is one odd character responsible for this,
  which
  I reproduce bellow:
  In case you cannot see it, it looks like a right arrow, but it is not
 the
  one you get from microsoft word in menu insert symbol.
 
  I think my dat file is broken and that funny character is an EOL marker
  that
  makes R not read the rest of the file. I am sure the character is there
 by
  chance but I fear that it might be present in some other big files I
 have
  to
  work with as well. So, is there any clever way to remove this
 inconvenient
  character in R avoiding having to edit the file in notepad and remove
 it
  manually?
 
  Code I am using:
 
  read.csv(new3.dat, header=F)
 
  Warning message:
  In read.table(file = file, header = header, sep = sep, quote = quote,
  :
   incomplete final line found by readTableHeader on 'new3.dat'
 
 
  I think you should identify the offending line by using the count.fields
  function and fix it with an editor.
 
 
  --
  David
 
 
  I am working with R 2.10.1 in windows XP.
 
  Thanks in advance
 
  Jonas
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 http://www.r-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
 
 
  David Winsemius, MD
  Heritage Laboratories
  West Hartford, CT
 
 
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 



 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] End of line marker?

2010-03-03 Thread jonas garcia
Dear R users,

I am trying to read a huge file in R. For some reason, only a part of the
file is read. When I further investigated, I found that in one of my
non-numeric columns, there is one odd character responsible for this, which
I reproduce bellow:

In case you cannot see it, it looks like a right arrow, but it is not the
one you get from microsoft word in menu insert symbol.

I think my dat file is broken and that funny character is an EOL marker that
makes R not read the rest of the file. I am sure the character is there by
chance but I fear that it might be present in some other big files I have to
work with as well. So, is there any clever way to remove this inconvenient
character in R avoiding having to edit the file in notepad and remove it
manually?

 Code I am using:

read.csv(new3.dat, header=F)

Warning message:
In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on 'new3.dat'

I am working with R 2.10.1 in windows XP.

Thanks in advance

Jonas

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] axis labels

2009-10-14 Thread jonas garcia
Problem solved!
thanks
J

On Wed, Oct 14, 2009 at 12:31 AM, S Ellison s.elli...@lgc.co.uk wrote:

  They probably look different because the y-axis distance is to the
 bottom of the number and the x-axis to the top; character adjustment is
 putting the actual locations in the 'same' place but with opposing
 orientation.

 Try fooling about with the mgp argument in axis():

 par(mfrow=c(1,1), cex.axis = 0.5, cex.lab = 0.5)
 plot(1,1, axes = F)
 axis(1, mgp=c(3,0.7,0))
 axis(2, mgp=c(3,1,0))

  jonas garcia garcia.jona...@googlemail.com 10/13/09 5:58 PM 
 Dear list,
 why does the distance between the axis labels and the tick marks looks
 different for x axis and y axis in the plot (see code below).
 In fact, the x axis labels look furthest from the tickmarks than in the
 y
 axis.
 How can I make them look the same?

  par(mfrow=c(1,1), cex.axis = 0.5, cex.lab = 0.5)
 plot(1,1, axes = F)
 axis(1)
 axis(2)

 Thanks in advance

 Jonas

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 ***
 This email and any attachments are confidential. Any u...{{dropped:13}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] axis labels

2009-10-13 Thread jonas garcia
Dear list,
why does the distance between the axis labels and the tick marks looks
different for x axis and y axis in the plot (see code below).
In fact, the x axis labels look furthest from the tickmarks than in the y
axis.
How can I make them look the same?

 par(mfrow=c(1,1), cex.axis = 0.5, cex.lab = 0.5)
plot(1,1, axes = F)
axis(1)
axis(2)

Thanks in advance

Jonas

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with functions

2009-09-05 Thread jonas garcia
Thanks Baptiste



On Fri, Sep 4, 2009 at 5:13 PM, baptiste auguie 
baptiste.aug...@googlemail.com wrote:

 Hi,

 I think you've got a problem with environments,

 testA-function(input=1)

 {

  dat - data.frame(A=seq(input,5), B=seq(6,10))
  vec.names- c(a, b)
  env - new.env()

 for(i in 1:ncol(dat))
  {
tab- dat[,i]-1
assign(vec.names[i], tab, env=env)
  }
  do.call(rbind, lapply(vec.names, get, env=env))
 }

 testA()

 But more generally, I doubt your construct using assign and get is the most
 natural way to reach your goal in R.

 HTH,

 baptiste


 2009/9/4 jonas garcia garcia.jona...@googlemail.com

  Hi all,



 I have got 2 function (see bellow) which are simplifications of what I
 need
 to do. These functions are precisely the same, except for the last line.



 My question is, why doesn't function testA work in the same way as
 function
 testB.

 Both functions produce two objects, a and b that must merged with
 rbind.
 The difference is that in testA, I specify the name of the objects while
 in
 testA I am stating which objects I want to bind from a character vector.



 What's more, if I just run the code without a function (example given
 below
 as well), they both work...

 Why is this?



 Thanks in advance



 Jonas





 testA-function(input)

 {

  dat- data.frame(A=seq(input,5), B=seq(6,10))

  vec.names- c(a, b)

  for(i in 1:ncol(dat))

  {

tab- dat[,i]-1

assign(vec.names[i], tab)

  }



  do.call(rbind, lapply(vec.names, get))

 }







 testB-function(input)

 {

  dat- data.frame(A=seq(input,5), B=seq(6,10))

  vec.names- c(a, b)

  for(i in 1:ncol(dat))

  {

tab- dat[,i]-1

assign(vec.names[i], tab)

  }



  rbind(a,b)

 }







 testA(1)

 Error in FUN(c(a, b)[[1L]], ...) : object 'a' not found



 testB(1)

  [,1] [,2] [,3] [,4] [,5]

 a01234

 b56789








 ###







  dat- data.frame(A=seq(1,5), B=seq(6,10))

  vec.names- c(a, b)

  for(i in 1:ncol(dat))

  {

tab- dat[,i]-1

assign(vec.names[i], tab)

  }



  do.call(rbind, lapply(vec.names, get))

 [,1] [,2] [,3] [,4] [,5]

 [1,]01234

 [2,]56789









 dat- data.frame(A=seq(1,5), B=seq(6,10))

  vec.names- c(a, b)

  for(i in 1:ncol(dat))

  {

tab- dat[,i]-1

assign(vec.names[i], tab)

  }



  rbind(a,b)

  [,1] [,2] [,3] [,4] [,5]

 a01234

 b56789

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 _

 Baptiste Auguié

 School of Physics
 University of Exeter
 Stocker Road,
 Exeter, Devon,
 EX4 4QL, UK

 http://newton.ex.ac.uk/research/emag
 __



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] help with functions

2009-09-04 Thread jonas garcia
Hi all,



I have got 2 function (see bellow) which are simplifications of what I need
to do. These functions are precisely the same, except for the last line.



My question is, why doesn't function testA work in the same way as function
testB.

Both functions produce two objects, a and b that must merged with rbind.
The difference is that in testA, I specify the name of the objects while in
testA I am stating which objects I want to bind from a character vector.



What's more, if I just run the code without a function (example given below
as well), they both work...

Why is this?



Thanks in advance



Jonas





testA-function(input)

{

  dat- data.frame(A=seq(input,5), B=seq(6,10))

  vec.names- c(a, b)

  for(i in 1:ncol(dat))

  {

tab- dat[,i]-1

assign(vec.names[i], tab)

  }



  do.call(rbind, lapply(vec.names, get))

}







testB-function(input)

{

  dat- data.frame(A=seq(input,5), B=seq(6,10))

  vec.names- c(a, b)

  for(i in 1:ncol(dat))

  {

tab- dat[,i]-1

assign(vec.names[i], tab)

  }



  rbind(a,b)

}







testA(1)

Error in FUN(c(a, b)[[1L]], ...) : object 'a' not found



testB(1)

  [,1] [,2] [,3] [,4] [,5]

a01234

b56789







###







  dat- data.frame(A=seq(1,5), B=seq(6,10))

  vec.names- c(a, b)

  for(i in 1:ncol(dat))

  {

tab- dat[,i]-1

assign(vec.names[i], tab)

  }



  do.call(rbind, lapply(vec.names, get))

 [,1] [,2] [,3] [,4] [,5]

[1,]01234

[2,]56789









dat- data.frame(A=seq(1,5), B=seq(6,10))

  vec.names- c(a, b)

  for(i in 1:ncol(dat))

  {

tab- dat[,i]-1

assign(vec.names[i], tab)

  }



  rbind(a,b)

  [,1] [,2] [,3] [,4] [,5]

a01234

b56789

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] cbind objects using character vectors

2009-09-02 Thread jonas garcia
Thanks Erik and Henrique,

That's what I was after.
Jonas



On Tue, Sep 1, 2009 at 8:08 PM, Henrique Dallazuanna www...@gmail.comwrote:

 Try this:

  sapply(vec.names, get)

 But for this example, you don't need for, try:

  dat - 1

   On Tue, Sep 1, 2009 at 2:52 PM, jonas garcia 
 garcia.jona...@googlemail.com wrote:

  Dear list,



 I have a character vector such vec.names- c(a, b)

 It happens that I have also two R objects called a and b that I would
 like to merge. Is it possible to

 do something like cbind(vec.names[1], vec.names[2]) ending up with the
 same
 result as cbind(a,b)



 Bellow is a reproducible example of what I need to to:



 dat- data.frame(A=seq(1,5), B=seq(6,10))

 vec.names- c(a, b)

 for(i in 1:ncol(dat))

 {

 tab- dat[,i]-1

 assign(vec.names[i], tab)

 }



 cbind(vec.names[1], vec.names[2])

 [,1] [,2]

 [1,] a  b





 But I was looking after the following result (using vec.names):



 cbind(a,b)

 a b

 [1,] 0 5

 [2,] 1 6

 [3,] 2 7

 [4,] 3 8

 [5,] 4 9





 Thanks in advance



 Jonas

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] cbind objects using character vectors

2009-09-01 Thread jonas garcia
Dear list,



I have a character vector such vec.names- c(a, b)

It happens that I have also two R objects called a and b that I would
like to merge. Is it possible to

do something like cbind(vec.names[1], vec.names[2]) ending up with the same
result as cbind(a,b)



Bellow is a reproducible example of what I need to to:



dat- data.frame(A=seq(1,5), B=seq(6,10))

vec.names- c(a, b)

for(i in 1:ncol(dat))

{

tab- dat[,i]-1

assign(vec.names[i], tab)

}



cbind(vec.names[1], vec.names[2])

 [,1] [,2]

[1,] a  b





But I was looking after the following result (using vec.names):



cbind(a,b)

 a b

[1,] 0 5

[2,] 1 6

[3,] 2 7

[4,] 3 8

[5,] 4 9





Thanks in advance



Jonas

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] vector fragment

2009-05-16 Thread jonas garcia
Dear R users:



I have got a simple question that has been bothering me for a while.

Given a certain character vector, I would like to get in a separate vector a
fragment of text, in this case the 3rd and 4th letters of each element.



So, if:



v- c(“stratosphere”, “mesosphere”, “troposphere”)



I want to obtain a different vector like this:



c(“ra”, “so”, “op”)



Thanks in advance for your help



Jonas

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] missing argument

2008-12-11 Thread jonas garcia
Thank you all for the replies. Problem soved!
J


On 12/10/08, Bert Gunter gunter.ber...@gene.com wrote:

 I believe the usual practice in this case is simply to give default values
 for arguments:
 function(x, y, opt.arg1 = 0, opt.arg2 = sin(1),...)

 If you haven't already done so, perusal of An Introduction to R --
 especially the Named Arguments and Defaults -- would be appropriate.

 Cheers,
 Bert Gunter



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On
 Behalf Of Tony Breyal
 Sent: Wednesday, December 10, 2008 1:01 PM
 To: r-help@r-project.org
 Subject: Re: [R] missing argument

 ?missing

 never used it myself, but looks like it might help you  :-)

 Tony Breyal.

 On 10 Dec, 19:09, jonas garcia garcia.jona...@googlemail.com
 wrote:
  Dear list,
  I have a question and I'm going to give an example of my problem
 
  f- function(d1, d2, d3)
  {
  d- d1*d2/d3
  return(d)
 
  }
 
  v1- 1
  v2- 2
  If I try
  f(v1, v2, v3)
  Error in f(v1, v2, v3) : object v3 not found
 
  I obviously got the above error message.
  I would like to add something to my function to allow me to get a certain
  value (say zero)
  if one of the arguments is not provided (in this case v3).
 
  Thanks in advance
  J
 
  [[alternative HTML version deleted]]
 
  __
  r-h...@r-project.org mailing
 listhttps://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting
 guidehttp://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] missing argument

2008-12-10 Thread jonas garcia
Dear list,
I have a question and I'm going to give an example of my problem

f- function(d1, d2, d3)
{
d- d1*d2/d3
return(d)
}

v1- 1
v2- 2
If I try
f(v1, v2, v3)
Error in f(v1, v2, v3) : object v3 not found

I obviously got the above error message.
I would like to add something to my function to allow me to get a certain
value (say zero)
if one of the arguments is not provided (in this case v3).

Thanks in advance
J

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] extract bits of a character vector

2008-10-22 Thread jonas garcia
Dear list:



I have the following problem: From a vector like this:

vec- c(mud_1999_area_A, gravel_2004_area_F)



I would like to get the year in a separate vector, such



y- c(1999, 2004)



I´ve been looking to grep() but I'm not sure how to do this.
Help?
Thanks in advance
J

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extract bits of a character vector

2008-10-22 Thread jonas garcia
Thank you all for the useful responses. Problem solved!
J

On Thu, Oct 23, 2008 at 12:14 AM, Duncan Murdoch [EMAIL PROTECTED]wrote:

  On 22/10/2008 5:02 PM, jonas garcia wrote:

 Dear list:



 I have the following problem: From a vector like this:

 vec- c(mud_1999_area_A, gravel_2004_area_F)



 I would like to get the year in a separate vector, such



 y- c(1999, 2004)



 I´ve been looking to grep() but I'm not sure how to do this.


 You want sub() or gsub().  For example, if the year is always the only
 digits in the string, then

 gsub([^[:digit:]], , vec)

 (which says delete all non-digits).

 Duncan Murdoch


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.