Creating an empty data.frame with only column names - R

0 votes
I want to create an empty dataframe with these column names: (Fruit, Cost, Quantity). No data, just these column names.
May 24, 2018 in Data Analytics by DataKing99
• 8,100 points
6,781 views

8 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
Fruit_Market<-data.frame(fruit=character(0),cost=numeric(0),quantity=integer(0))

You would have to create a data.frame by using only 0-length variables and it'll give you an empty data.frame.

answered May 24, 2018 by Bharani
• 4,550 points
0 votes

You can either NA values

data.frame(fruit=NA, cost=NA, quantity=NA)[numeric(0), ]
answered Dec 10, 2018 by Priyaj
0 votes
You can set dynamic values to your rows. Here the y length will be dynamic.

y <- data.frame(fruit=charector(), cost=numeric(), quantity=numeric())
answered Dec 10, 2018 by Keshav
0 votes
The most efficient way would be:

y <- read.csv(text="fruit,cost,quantity")
answered Dec 10, 2018 by Denis
0 votes

Try this:

names <- c("fruit","cost","quantity")
df <- data.frame()
for (k in names) df[[k]] <- as.character()
answered Dec 10, 2018 by Vedant
0 votes

You can use as.data.frame like this:

as.data.frame(x, row.names = NULL, optional = FALSE, …)

make sure row.names is NULL 

answered Dec 10, 2018 by Vaibhav
0 votes

as.data.frame is a good choice. For more detailed, have a look at the documentation.

answered Dec 10, 2018 by Kaksha
0 votes
Please try following code snippet.
df <- data.frame(matrix(ncol = 3, nrow = 0))
x <- c("name", "age", "gender")
colnames(df) <- x
For more detail, Please check this link
https://stackoverflow.com/questions/32712301/create-empty-data-frame-with-column-names-by-assigning-a-string-vector

Thanks.

answered Mar 7 by RajkumarManiRaja

Related Questions In Data Analytics

0 votes
1 answer

How to change column names of a Data frame?

Easiest way: names(prices)[1]<-paste0("old") names(prices)[2]<-paste0("new") names(prices)[3]<-paste0("best") #or by using colnames colnames(prices)<-c("old","new","best") prices old ...READ MORE

answered Apr 11, 2018 in Data Analytics by DeepCoder786
• 1,700 points
27 views
0 votes
1 answer

How to order data frame rows according to vector with specific order using R?

You can try using match: data <- data.frame(alphabets=letters[1:4], ...READ MORE

answered Apr 30, 2018 in Data Analytics by darklord
• 6,140 points
43 views
0 votes
1 answer

How can I append rows to an R data frame?

Consider a dataSet i.e cicar(present under library ...READ MORE

answered May 8, 2018 in Data Analytics by zombie
• 3,690 points
27 views
0 votes
1 answer

How to filter a data frame with dplyr and tidy evaluation in R?

Requires the use of map_df to run each model, ...READ MORE

answered May 16, 2018 in Data Analytics by DataKing99
• 8,100 points
50 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,700 points
66 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,700 points
37 views
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,700 points
31 views
0 votes
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
60 views
0 votes
1 answer

Filtering R data-frame with multiple conditions

You can use the 'filter' function from ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
3,155 views
0 votes
1 answer

Converting R data-frame to h2o object

All you have to do is run ...READ MORE

answered Apr 2, 2018 in Data Analytics by Bharani
• 4,550 points
419 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.