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,130 points
12,246 views

9 answers to this question.

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
0 votes

Will the below code work to create a empty dataframe?

v=data.frame(fruit=NA, cost=NA, quantity=NA)

It show columns with no data in row.

answered Aug 1 by preeti

Related Questions In Data Analytics

0 votes
2 answers

How to change column names of a Data frame?

Try this way - names(data frame) <- ...READ MORE

answered Aug 26 in Data Analytics by anonymous
• 25,660 points
69 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
68 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
47 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,130 points
92 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
109 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
68 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
85 views
0 votes
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21 in Data Analytics by anonymous
• 25,660 points
119 views
0 votes
2 answers

Filtering R data-frame with multiple conditions

librarry(dplyr) dataset >%> filter((a ==1,b>15 ) | (a==2,b&g ...READ MORE

answered Aug 8 in Data Analytics by anonymous
5,420 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
534 views