How about:
df <- data.frame(matrix(ncol = 3, nrow = 0)) x <- c("name", "age", "gender") colnames(df) <- x
To do all these operations in one-liner:
setNames(data.frame(matrix(ncol = 3, nrow = 0)), c("name", "age", "gender")) #[1] name age gender #<0 rows> (or 0-length row.names)
Or
data.frame(matrix(ncol=3,nrow=0, dimnames=list(NULL, c("name", "age", "gender"))))
Related Posts:
- Insert a blank column in dataframe
- Convert data.frame columns from factors to characters
- Convert data.frame column to a vector?
- Converting from a character to a numeric data frame
- Renaming column names in Pandas
- Delete a column from a Pandas DataFrame
- Selecting multiple columns in a Pandas dataframe
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Get statistics for each group (such as count, mean, etc) using pandas GroupBy?
- Writing a pandas DataFrame to CSV file
- Adding new column to existing DataFrame in Python pandas
- How to change the order of DataFrame columns?
- Create a Pandas Dataframe by appending one row at a time
- How do I select rows from a DataFrame based on column values?
- How do I get the row count of a Pandas DataFrame?
- Convert pandas dataframe to NumPy array
- Convert pandas Series to DataFrame
- How do I get the row count of a Pandas DataFrame?
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- ‘DataFrame’ object has no attribute ‘sort’
- ‘DataFrame’ object has no attribute ‘sort’
- Rename Pandas DataFrame Index
- Convert DataFrame column type from string to datetime, dd/mm/yyyy format
- Get a list from Pandas DataFrame column headers
- What is dtype(‘O’), in pandas?
- Replace a value in a data frame based on a conditional (`if`) statement
- How to read in .HTM into R as a data frame?
- How to take column-slices of dataframe in pandas
- Find duplicate values in R
- Transpose a data frame
- ggplot geom_text font size control
- What’s the difference between lapply and do.call?
- Python: create a pandas data frame from a list
- Initial value in ‘vmmin’ is not finite even when changing the starting value
- Convert a Pandas DataFrame to a dictionary
- Insert picture/table in R Markdown
- Test if a vector contains a given element
- How to remove outliers from a dataset
- Create a Pandas Dataframe by appending one row at a time
- “length of ‘dimnames’ [2] not equal to array extent” on one of two very similar sets
- Mean per group in a data.frame
- How to install RHadoop packages (Rmr, Rhdfs, Rhbase)?
- Error in dev.off() : cannot shut down device 1 (the null device)
- standard deviation on dataframe does not work
- Warning message: In `…` : invalid factor level, NA generated
- Dropping Multiple Columns from a data frame using Python
- promise already under evaluation: recursive default argument reference or earlier problems?
- Aggregate multiple columns at once
- Error in model.frame.default: variable lengths differ
- pandas dataframe convert column type to string or categorical
- Plot two graphs in same plot in R
- KNN in R: ‘train and class have different lengths’?
- Pandas DataFrame: replace all values in a column, based on condition
- Remove quotes from a character vector in R
- Pandas – How to flatten a hierarchical index in columns
- dplyr: “Error in n(): function should not be called directly”
- how to increase the limit for max.print in R
- Filter data.frame rows by a logical condition
- How to get a value from a cell of a dataframe?
- Replace NA with 0 in a data frame column [duplicate]
- How to plot 3D scatter diagram using ggplot?
- Error while creating heatmaps – NA/NaN/Inf in foreign function call (arg 11)
- Pandas split DataFrame by column value
- Groupby value counts on the dataframe pandas
- Conditional mean statement
- Pandas index column title or name
- Warning in GLM analysis
- What does ‘length of ‘dimnames’ [1] not equal to array extent’ mean?
- Print string and variable contents on the same line in R
- Does R have a wildcard expression (such as an asterisk (*))?
- How to add pandas data to an existing csv file?
- Simple for loop in R producing “replacement has length zero” in R
- Removing punctuations from text using R
- How to find out which package version is loaded in R?
- How to solve it. error:Error in data[[rowvar]] : attempt to select less than one element
- How to melt and cast dataframes using dplyr?
- How to unload a package without restarting R
- if else function in pandas dataframe
- Read data (.dat file) with Pandas
- How to convert index of a pandas dataframe into a column
- Launching R help: Error in file(out, “wt”) : cannot open the connection
- pandas comparison raises TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
- Reset par to the default values at startup
- How to increase the font size of ggtitle in ggplot2
- Error in G * t(hat) : non-conformable arrays
- Error: isTRUE(gpclibPermitStatus()) is not TRUE
- How to counter the ‘non-numeric matrix extent’ error in R?
- What does is.na() applied to non-(list or vector) of type ‘NULL’ mean?
- error r: invalid subscript type “closure” in a simple regression
- Merge two rows in data.frame
- Get the list of installed packages by user in R
- How to access the last value in a vector?
- Mask output of `The following objects are masked from….:` after calling attach() function
- Construct a manual legend for a complicated plot
- Logical operators for Boolean indexing in Pandas
- Error: x must be atomic for ‘sort.list’
- Transposing in dplyr
- Compare two columns using pandas
- How to create lag variables
- When trying to replace values, “missing values are not allowed in subscripted assignments of data frames”