Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's always difficult if you are primarily familiar with only one programming language when you try to learn another that works differently, because you expect to think through a problem in a different way, and these incorrect expectations cause problems. It would be very difficult to have an introductory guide that is appropriate for students coming from each of the other languages ('you're going to think you should do X, but in R, you should do Y'). However, I can assure you that R was not designed to be ambiguous. </p> <p>Mostly, you are simply going to have to get an introductory guide and plod through it. At first, it will be a lot of work, and frustrating, but that's the only way. In the end, it will get easier. Perhaps I can tell you a couple of things to jumpstart the process: </p> <ul> <li>a <code>list</code> is just an ordered set of elements. This can be of any length, and contain any old type of thing. For example, <code>x &lt;- list(5, "word", TRUE)</code>. </li> <li>a <code>vector</code> is also an ordered set of elements. Although it can be of any length, the elements must all be of the same type. For example, <code>x &lt;- c(3,5,4)</code>, <code>x &lt;- c("letter", "word", "a phrase")</code>, <code>x &lt;- c(TRUE, FALSE, FALSE, TRUE)</code>. </li> <li>a <code>matrix</code> is a vector of vectors, where all component vectors are of the same length and type. For example, <code>x &lt;- matrix(c("a", "b", "c", "d"), ncol=2)</code>. </li> <li>a <code>data.frame</code> is a list of vectors, where all component vectors are of the same length, but do NOT have to be of the same type. For example, <code>x &lt;- data.frame(category=c("blue", "green"), amount=c(5, 30), condition.met=c(TRUE, FALSE))</code>. </li> </ul> <hr> <p><em>(response to comments:)</em> </p> <ul> <li>The function <a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/c.html" rel="nofollow noreferrer">?c</a> is for <em>concatenation</em>; <code>c(c("a", "b"), c("c", "d"))</code>, will not create a matrix, but a longer vector from two shorter vectors. The function <a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/cbind.html" rel="nofollow noreferrer">?cbind</a> (to bind columns together), or <code>rbind()</code> (to bind rows together), will create a matrix. </li> <li>I don't know of a single function that will output the type of any object. The closest thing is probably <a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/class.html" rel="nofollow noreferrer">?class</a>, but this will sometimes give, e.g., "integer", where I think you want "vector". There are also <code>mode()</code>, and <code>typeof()</code>, which are related, but aren't quite what you're looking for. Find out more about the distinctions among these <a href="https://stats.stackexchange.com/questions/3212/mode-class-and-type-of-r-objects">here</a> and <a href="https://stackoverflow.com/questions/6258004/r-types-and-classes-of-variables">here</a>. To check whether an object is a <em>specific</em> type you can use <code>is.&lt;specific type&gt;()</code>, e.g., <a href="http://rss.acs.unt.edu/Rdoc/library/base/html/vector.html" rel="nofollow noreferrer">?is.vector</a>. </li> <li>To <em>coerce</em> (i.e., 'cast') an object to a specific type, you can use <code>as.vector()</code>, but this will only work if the conditions (e.g., noted above) are met. </li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload