data.frame() Function
Good! Now you can see that data frames can be used to connect different data types. In the previous chapter, you considered one of the build-in datasets. How can we create a data frame with our data?
It can be done by using data.frame()
function. This function receives vectors or lists (which we will consider in the next section) as columns. The names for columns are variable's names. For example, let's create a data frame with abstract information on three people.
12345678# Data name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") # Creating a data frame test <- data.frame(name, age, gender) test # Outputting the data frame
See, the names for columns come from variables names.
Swipe to start coding
Given two vectors: items
and prices
containing the names and prices of goods in an abstract local furniture store. Your tasks are:
- Create a data frame named
store
with two columns,items
andprices
(these are respective variables names). - Output
store
variable value.
Solution
Merci pour vos commentaires !
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Can you explain what each part of the code does?
What other data types can I use in a data frame?
How can I add more rows to this data frame?
Awesome!
Completion rate improved to 2.27
data.frame() Function
Glissez pour afficher le menu
Good! Now you can see that data frames can be used to connect different data types. In the previous chapter, you considered one of the build-in datasets. How can we create a data frame with our data?
It can be done by using data.frame()
function. This function receives vectors or lists (which we will consider in the next section) as columns. The names for columns are variable's names. For example, let's create a data frame with abstract information on three people.
12345678# Data name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") # Creating a data frame test <- data.frame(name, age, gender) test # Outputting the data frame
See, the names for columns come from variables names.
Swipe to start coding
Given two vectors: items
and prices
containing the names and prices of goods in an abstract local furniture store. Your tasks are:
- Create a data frame named
store
with two columns,items
andprices
(these are respective variables names). - Output
store
variable value.
Solution
Merci pour vos commentaires !
Awesome!
Completion rate improved to 2.27single