Questions about R Basics

Hi,

I'm still a beginner in the DA field and I have two quick fundamental questions:

  1. why vectors were made so that they can have only one type of data unlike lists and tuples in Python?
  2. why indexing in R starts with 1 unlike python?

Thanks,

Hello,

In regards to your questions:

  1. Vectors in R are indeed all of the same class, but it is perfectly possible to have lists containing different classes in R as well.
vec = c(1, "A", T)
sapply(vec, class)
#>           1           A        TRUE 
#> "character" "character" "character"


lst =list(1, "A", T)
sapply(lst, class)
#> [1] "numeric"   "character" "logical"

Created on 2022-04-03 by the reprex package (v2.0.1)

  1. R is based on Fortran, a language that also has indexing 1 the same as other related languages like Matlab. Since these languages are more used by mathematicians / statisticians, indexing starting at 1 is more logical as this is the way it is defined in mathematics

Hope this helps,
PJ

2 Likes

indeed it does thanks for your help @pieterjanvc :slightly_smiling_face: :slightly_smiling_face:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.