Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a column in R dataframe [duplicate]

Tags:

dataframe

r

Possible Duplicate:
Drop Columns R Data frame

Suppose, I have the following dataframe, and want to delete column "dataB" what would be R command for that?

y <- data.frame(k1=c(101,102,103,104,105,106,107,108),
                B=c(11,12,13,NA,NA,16,17,18), 
                dataB=11:18) 
like image 512
M.Qasim Avatar asked Nov 26 '12 05:11

M.Qasim


People also ask

How do I remove duplicate columns from a data frame?

To drop duplicate columns from pandas DataFrame use df. T. drop_duplicates(). T , this removes all columns that have the same data regardless of column names.

How do I remove duplicates from a DataFrame in R?

Remove Duplicate rows in R using Dplyr – distinct () function. Distinct function in R is used to remove duplicate rows in R using Dplyr package. Dplyr package in R is provided with distinct() function which eliminate duplicates rows with single variable or with multiple variable.

How do I remove a column from a DataFrame in R?

The most easiest way to drop columns is by using subset() function. In the code below, we are telling R to drop variables x and z. The '-' sign indicates dropping variables. Make sure the variable names would NOT be specified in quotes when using subset() function.


1 Answers

This: y$B <- NULL removes column B from dataframe y.

like image 116
sashkello Avatar answered Oct 23 '22 10:10

sashkello