Use drop=FALSE
> x <- df[,1, drop=FALSE]
> x
A
1 10
2 20
3 30
From the documentation (see ?"["
) you can find:
If drop=TRUE the result is coerced to the lowest possible dimension.
More Related Contents:
- Filter data.frame rows by a logical condition
- Subset data frame based on number of rows per group
- Opposite of %in%: exclude rows with values specified in a vector
- How to drop columns by name in a data frame
- Subset / filter rows in a data frame based on a condition in a column
- Subset dataframe by multiple logical conditions of rows to remove
- Filtering a data frame on a vector [duplicate]
- Subset data frame based on multiple conditions [duplicate]
- Subset of rows containing NA (missing) values in a chosen column of a data frame
- dplyr – filter by group size
- How to subset data in R without losing NA rows?
- Using grep to help subset a data frame
- Filter data frame rows based on values in vector
- Selecting columns in R data frame based on those *not* in a vector
- Return df with a columns values that occur more than once [duplicate]
- Undefined columns selected when subsetting data frame
- Quickly reading very large tables as dataframes
- Convert a list to a data frame
- Split a large dataframe into a list of data frames based on common value in column
- Splitting a dataframe string column into multiple different columns [duplicate]
- calculate the mean for each column of a matrix in R
- Subset rows in a data frame based on a vector of values
- Creating a new variable from a lookup table
- R gotcha: logical-and operator for combining conditions is & not &&
- Read and rbind multiple csv files
- How I can select rows from a dataframe that do not match?
- Join two data frames in R based on closest timestamp
- Count unique values for every column
- What you can do with a data.frame that you can’t with a data.table?
- Override column types when importing data using readr::read_csv() when there are many columns