Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined columns selected when subsetting data frame

I have a data frame, str(data) to show more about my data frame the result is the following:

> str(data) 'data.frame':   153 obs. of  6 variables: $ Ozone  : int  41 36 12 18 NA 28 23 19 8 NA ... $ Solar.R: int  190 118 149 313 NA NA 299 99 19 194 ... $ Wind   : num  7.4 8 12.6 11.5 14.3 14.9 8.6 13.8 20.1 8.6 ... $ Temp   : int  67 72 74 62 56 66 65 59 61 69 ... $ Month  : int  5 5 5 5 5 5 5 5 5 5 ... $ Day    : int  1 2 3 4 5 6 7 8 9 10 ... 

However, for example, when I want to subset the amounts of Ozone above 14 I use the following code which gives me an error:

>  data[data$Ozone > 14 ] 

Error in [.data.frame(data, data$Ozone > 14) : undefined columns selected

like image 416
CreamStat Avatar asked Oct 06 '13 05:10

CreamStat


People also ask

What does it mean by undefined columns selected in R?

R ProgrammingServer Side ProgrammingProgramming. The error “undefined columns selected when subsetting data frame” means that R does not understand the column that you want to use while subsetting the data frame. Generally, this happens when we forget to use comma while subsetting with single square brackets.

How do I add a column to a Dataframe in R?

1 Adding new columns. You can add new columns to a dataframe using the $ and assignment <- operators. To do this, just use the df$name notation and assign a new vector of data to it. As you can see, survey has a new column with the name sex with the values we specified earlier.


1 Answers

You want rows where that condition is true so you need a comma:

data[data$Ozone > 14, ] 
like image 155
Ari B. Friedman Avatar answered Oct 13 '22 06:10

Ari B. Friedman