in Education by
I want to remove some questions from data frame, I know how to delete them individually using df$x <- NULL But I want to know a shortcut to perform this task. I know how to drop columns using integer index using this command: df <- df[ -c(1, 3:6, 12) ] But I fear this might change the relative position of my variables. So, Is there a better way than dropping each column one by one? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Subset Command can be useful if you know which column you want: df <- data.frame(q = 2:11, e = 3:12, w = 4:13) df <- subset(df, select = w(q, w)) Or you can also drop columns using: df <- subset(df, select = -w(q, w)) Alternatively you can also use drop argument if you want to keep one column as a data frame, for this use: keeps <- "V" DF[ , keeps, drop = FALSE] To drop unnecessary dimensions use drop=True and finally return a vector with the values of column V Enjoy Learning. Cheers.

Related questions

0 votes
    I have a dataframe: > myvec name order_no 1 Nehal 12 2 sejal 14 3 sejal 16 4 shyam 11 5 Nehal 12 6 Sejal 16 ... Sejal 3 Shyam 1 Ram 1 Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I want to bind two data frames with different set of columns and I also want to retain all the columns that fails to ... do that in R? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I want a way to create a empty data.frame in R, I just want to point out data types for each column and name it without any row created. df...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me a quick way to convert a nested list of data whose length is 100 and each item is a list of ... 100 rows and 10 columns? I am attaching a sample data: 5...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    Here are two data frames : df1 = data.frame(CId = a(1:6), Item = b(rep("TV", 3), rep("Book", 3 ... I do a SQL style select statement Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    How can I sort a data.frame by multiple columns. E.x. I would like to sort the column q(descending) by column f (ascending) dd...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    Can someone tell me a function which can return a specified no. of rows picked randomly without any replacement from a DataFrame in R? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Want to remove the lines from data frame from that : Have NAs across all columns a b c d e f 1 YASH00000206234 0 ... 0 1 2 3 2 Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    How to replace the values of NA with zeros in some column and data frame I have? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    I want to remove some questions from data frame, I know how to delete them individually using df$x...
asked Oct 30, 2021 in Education by JackTerrance
0 votes
    I have a data which consists of two columns "Students" & "points" x...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I have code that at one place ends up with a list of data frames which I really want to convert ... starting with (this is grossly simplified for illustration): listOfDataFrames...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a data frame called "newprice" (see below) and I want to change the column names in my program in R. > newprice ... 164 In fact, this is what am doing: names(newprice)[1]...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    import pandas as pd from itertools import combinations, product, permutations MH_P= ["Maria Herrera"] OP_P= ["Oscar ... i solve it? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    _________ extract a subset of rows from a data frame based on logical conditions. (a) rename (b) filter ( ... Analysis of R Programming Select the correct answer from above options...
asked Feb 9, 2022 in Education by JackTerrance
...