R Data Types
Following is the description of above-mentioned data types:
names = c( "Chris", "James", "Ted")
# executing names prints following:
> names
[1] "Chris" "James" "Ted"
age = c(48, 56, 50)
# executing age prints following:
> age
[1] 48 56 50
# The list below consists of two vectors, names and age which consists of two different data types
l = list( names, age )
# executing l would print following:
> l
[[1]]
[1] "Chris" "James" "Ted"
[[2]]
[1] 48 56 50
# Following is another example showing character, integer and numeric stored in the list
l = list( "Chris", 28, 129000.5 )
# executing l would display following:
> l
[[1]]
[1] "Chris"
[[2]]
[1] 28
[[3]]
[1] 129000.5
gender = c("male", "female")
f = factor(gender)
# Typing command f prints following:
> f
[1] male female
Levels: female male
# Let's store names and age vector in the data frame
d = data.frame( names, age )
# executing d would print following:
> d
names age
1 Chris 48
2 James 56
3 Ted 50
From example, you may infer that data frame needs to have vector of same size.
m = matrix( 1:10, nrow=2, ncol=5)
# executing m would print following:
> m
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10
In code example above, 1:0 represents the sequence of number starting from going upto 10. nrow represents number of rows. ncol represents number of columns.
a = array( 1:6, c(2,3))
# executing a would print following:
> a
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
# Lets look at another example
a = array( 1:6, c(2,1,3))
# executing a would print following:
> a
, , 1
[,1]
[1,] 1
[2,] 2
, , 2
[,1]
[1,] 3
[2,] 4
, , 3
[,1]
[1,] 5
[2,] 6
Pay attention to multiple dimension owing to data stored in array.
Following are different web pages which describes R data types in a great manner:
Additionally, you could learn details on R data types by typing following on R console:
Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…
Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…
Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…
Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…
The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…
Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…