In Matlab, an array can be created from 1 - 30 using the command similar to R which is 1:30. Then, to make the array step by 0.1 the command is 1:0.1:30 which is 1, 1.1, 1.2,...,29.9,30. How can I do this in R? ----- In theory, practice and theory are the same. In practice, they are not - Albert Einstein -- View this message in context: http://r.789695.n4.nabble.com/create-arrays-tp3503988p3503988.html Sent from the R help mailing list archive at Nabble.com.
On Fri, May 06, 2011 at 12:11:30PM -0700, Schatzi wrote:> In Matlab, an array can be created from 1 - 30 using the command similar to R > which is 1:30. Then, to make the array step by 0.1 the command is 1:0.1:30 > which is 1, 1.1, 1.2,...,29.9,30. How can I do this in R? > ...This may well be a hack, but> 10:300/10seemed to do it for me. Peace, david -- David H. Wolfskill r at catwhisker.org Depriving a girl or boy of an opportunity for education is evil. See http://www.catwhisker.org/~david/publickey.gpg for my public key. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110506/c4af7b8c/attachment.bin>
I can get around it by doing something like: as.matrix(rep(1,291))*row(as.matrix(rep(1,291)))/10+.9 I was just hoping for a simple command. Schatzi wrote:> > In Matlab, an array can be created from 1 - 30 using the command similar > to R which is 1:30. Then, to make the array step by 0.1 the command is > 1:0.1:30 which is 1, 1.1, 1.2,...,29.9,30. How can I do this in R? >----- In theory, practice and theory are the same. In practice, they are not - Albert Einstein -- View this message in context: http://r.789695.n4.nabble.com/create-arrays-tp3503988p3503998.html Sent from the R help mailing list archive at Nabble.com.
?seq -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Schatzi > Sent: Friday, May 06, 2011 1:12 PM > To: r-help at r-project.org > Subject: [R] create arrays > > In Matlab, an array can be created from 1 - 30 using the command > similar to R > which is 1:30. Then, to make the array step by 0.1 the command is > 1:0.1:30 > which is 1, 1.1, 1.2,...,29.9,30. How can I do this in R? > > ----- > In theory, practice and theory are the same. In practice, they are not > - Albert Einstein > -- > View this message in context: http://r.789695.n4.nabble.com/create- > arrays-tp3503988p3503988.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
On Fri, May 6, 2011 at 12:11 PM, Schatzi <adele_thompson at cargill.com> wrote:> In Matlab, an array can be created from 1 - 30 using the command similar to R > which is 1:30. Then, to make the array step by 0.1 the command is 1:0.1:30 > which is 1, 1.1, 1.2,...,29.9,30. How can I do this in R?Hmm, in this case, I would do it slightly differently: seq(from = 1, to = 30, by = .1) Cheers, Josh> > ----- > In theory, practice and theory are the same. In practice, they are not - Albert Einstein > -- > View this message in context: http://r.789695.n4.nabble.com/create-arrays-tp3503988p3503988.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
Beautiful. -----Original Message----- From: Greg.Snow at imail.org [mailto:Greg.Snow at imail.org] Sent: Friday, May 06, 2011 02:17 PM To: Thompson, Adele - Adele_Thompson at cargill.com; r-help at r-project.org Subject: RE: [R] create arrays ?seq -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Schatzi > Sent: Friday, May 06, 2011 1:12 PM > To: r-help at r-project.org > Subject: [R] create arrays > > In Matlab, an array can be created from 1 - 30 using the command > similar to R > which is 1:30. Then, to make the array step by 0.1 the command is > 1:0.1:30 > which is 1, 1.1, 1.2,...,29.9,30. How can I do this in R? > > ----- > In theory, practice and theory are the same. In practice, they are not > - Albert Einstein > -- > View this message in context: http://r.789695.n4.nabble.com/create- > arrays-tp3503988p3503988.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
Some good suggestions, just (as always) be aware of floating-point imprecision. See FAQ 7.31> s <- seq(1,30,0.1) > s[8][1] 1.7> s[8] == 1.7[1] FALSE Just trying to forestall future questions :-) Dan Daniel Nordlund Bothell, WA USA> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] > On Behalf Of Adele_Thompson at cargill.com > Sent: Friday, May 06, 2011 12:18 PM > To: Greg.Snow at imail.org; r-help at r-project.org > Subject: Re: [R] create arrays > > Beautiful. > > -----Original Message----- > From: Greg.Snow at imail.org [mailto:Greg.Snow at imail.org] > Sent: Friday, May 06, 2011 02:17 PM > To: Thompson, Adele - Adele_Thompson at cargill.com; r-help at r-project.org > Subject: RE: [R] create arrays > > ?seq > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Center > Intermountain Healthcare > greg.snow at imail.org > 801.408.8111 > > > > -----Original Message----- > > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > > project.org] On Behalf Of Schatzi > > Sent: Friday, May 06, 2011 1:12 PM > > To: r-help at r-project.org > > Subject: [R] create arrays > > > > In Matlab, an array can be created from 1 - 30 using the command > > similar to R > > which is 1:30. Then, to make the array step by 0.1 the command is > > 1:0.1:30 > > which is 1, 1.1, 1.2,...,29.9,30. How can I do this in R? > > > > ----- > > In theory, practice and theory are the same. In practice, they are not > > - Albert Einstein > > -- > > View this message in context: http://r.789695.n4.nabble.com/create- > > arrays-tp3503988p3503988.html > > Sent from the R help mailing list archive at Nabble.com. > > > > ______________________________________________ > > R-help at 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 at 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.