Extract Certain Columns of a Data Frame in R (4 Examples) | Subset Variables by Column Name

preview_player
Показать описание

R programming code on how to extract columns of a data matrix:

x2 = c(7, 1, 1, 5),
x3 = c(9, 5, 4, 9),
x4 = c(3, 4, 1, 2))

data[ , c("x1", "x3")] # Subset by name

data[ , c(1, 3)] # Subset by position

subset(data, select = c("x1", "x3")) # Subset with select argument

library("dplyr") # Load dplyr R package

data %>% select(x1, x3) # Subset with select function
Рекомендации по теме
Комментарии
Автор

Hey i am trying to extract a column of values from the R data frame to copy it into Excel sheet but it isnt happening how do I do that?

muhammadhasanaziz
Автор

Hi what if there are several columns with the same column name? I tried and only the first column with that name can be extracted.

xueqihou
Автор

if i have a column of data and i want to just select the first 10 in the column how would i go about doing this

C-G
Автор

Thanks, I visualized 4 columns that I wanted, but how do i save it as a new csv file?

tommytran
Автор

Please show Working
I Can't Seperate Columns of "co2" inbuilt dataset of R.
Throws error of being "Atomic Vector"

Hassan_MM.
Автор

Good work but i keep on getting this feedback (Error in `[.data.frame`(heart, , c("age", "sex", "cp", "target")) :
undefined columns selected)

gadthompson
Автор

Error in C("date", "item_cnt_day") : object not interpretable as a factor

mainakray
Автор

Hi, good video but If I have a wave how can I take and separate the values ​​of the crests starting from a certain threshold?

Orange-xwlt
Автор

Very nice explanation..
I have a question..
I have a column of INJ_BODY_PART, it consists of data like KNEE/PATELLA, FINGER(S)/THUMB, BACK (MUSCLES/SPINE/S-CORD/TAILBONE), MULTIPLE PARTS (MORE THAN ONE MAJOR), LOWERLEG/TIBIA/FIBULA, WRIST, CHEST (RIBS/BREAST BONE/CHEST ORGNS) and so on.. kindly help me with line of code.. how can I categorise them ..

poojamahesh