create dataframe or table in r
To create a dataframe or table in R, follow these steps:
- Use the data.frame() function to create a dataframe. For example:
my_dataframe <- data.frame(
ID = c(1, 2, 3, 4, 5),
Name = c("Alice", "Bob", "Charlie", "David", "Eve"),
Age = c(25, 30, 28, 33, 27)
)
- Alternatively, you can use the tibble() function from the dplyr package to create a tibble. For example:
library(dplyr)
my_tibble <- tibble(
ID = c(1, 2, 3, 4, 5),
Name = c("Alice", "Bob", "Charlie", "David", "Eve"),
Age = c(25, 30, 28, 33, 27)
)
- If you want to create a table, you can use the table() function to tabulate the data. For example:
my_table <- table(my_dataframe$Age)
These steps will enable you to create a dataframe or table in R.