The c() Function
In this page:
The c() Function
c() (combine) builds a vector out of individual values or merges existing vectors together. If the values have mixed types, R coerces them all to the most general common type, such as converting numbers to strings if any element is a character. This coercion rule is important to keep in mind when combining data from different sources.
Warning: c(1, 2, "three") coerces every element to character -- mixing types silently promotes the whole vector to the most general type.
Example: The c() Function
numbers <- c(1, 2, 3)
combined <- c(numbers, 4, 5)
print(combined)
mixed <- c(1, 2, "three")
print(mixed)
cat(class(mixed), "\n")
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: