[R] Using a for loop

Joshua Wiley jwiley.psych at gmail.com
Wed Oct 12 08:21:05 CEST 2011


You should read the posting guide again (at all?).  Among other
things, it suggests you should show what you have tried doing that did
not work (worst case it shows us you tried to figure it out on your
own before asking other people to freely give their time to solve your
problems, at best case, we only need to minimally tweak your code to
get you up and running and save time duplicating what you already did
that was close to right but not quite).  Did you try anything to get 1
to 65 in x and 66 to 130 in y?

Look at the documention for the extraction operator, which you can
access by typing at the console: ?"["

? typically brings up documentation, though you normally do not need
to quote function names, [ is special so it needs quotes around it.
By leaving the row index empty (that's the part before the comma), you
are selecting all rows.  If you only want to select rows 1 to 65, try:

1:65

which suggests

normtemp[1:65, 1]
normtemp[66:130, 1]

finally leading us to:

x <- normtemp[1:65, 1]
y <- normtemp[66:130, 1]

Thank you for indicating the package you are using and providing an
easy data example, though.

I hope this helps.

Cheers,

Josh




On Tue, Oct 11, 2011 at 10:58 PM, JohnnyJames <penguinrule1317 at aim.com> wrote:
> I am using the normtemp data set in UsingR package. I want to store all
> normtemp[,1] from 1 to 65 as x and normtemp[,1] from 66to 130 as y. How do I
> write code to do that from here:
>
>  > data(normtemp)
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Using-a-for-loop-tp3896903p3896903.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

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ link to the
posting guide I mentioned

> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list