Concept Flow - Numeric and character vectors
Start
Create vector
Check type: numeric or character?
Store numbers
Use vector
We start by creating a vector, then check if it holds numbers or text, and store accordingly for use.
nums <- c(10, 20, 30) chars <- c("a", "b", "c") print(nums) print(chars)
| Step | Action | Variable | Value | Output |
|---|---|---|---|---|
| 1 | Create numeric vector | nums | c(10, 20, 30) | |
| 2 | Create character vector | chars | c("a", "b", "c") | |
| 3 | Print numeric vector | nums | c(10, 20, 30) | [1] 10 20 30 |
| 4 | Print character vector | chars | c("a", "b", "c") | [1] "a" "b" "c" |
| 5 | End of code | Execution complete |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| nums | NULL | c(10, 20, 30) | c(10, 20, 30) | c(10, 20, 30) |
| chars | NULL | NULL | c("a", "b", "c") | c("a", "b", "c") |
Numeric and character vectors in R hold numbers or text.
Use c() to create vectors: nums <- c(1,2,3), chars <- c("a","b","c").
Vectors hold one type only; mixing types converts all to character.
Print vectors with print() or just variable name.
Vectors are basic building blocks for data in R.