- Creating Vectors
- Vector: 1D array of data elements with same datatype
- The c() function can be used to create vectors of objects by concatenating things together.
- Note that in the above example, T and F are short-hand ways to specify TRUE and FALSE. However,in general one should try to use the explicit TRUE and FALSE values when indicating logical values.
- You can also use the vector() function to initialize vectors.
- There are occasions when different classes of R objects get mixed together then R will convert implicitly into some class.
- Objects can be explicitly coerced from one class to another using the as.* functions, if available
- Sometimes, R can’t figure out how to coerce an object and this can result in NAs being produced.
- Single value variable also vector
- Create a named vector for playing cards
- Method 1:
- Method 2:
- Method 3:
- One more example : let us say you played cards Monday to Friday and record profit and loss as vector.
No comments:
Post a Comment