Reputation: 13
Ok, apologies for a real newbie question.
I'm just trying to plot two variables, one which is directly in my csv file and the other which is simply a division of two columns. See code below.
However when I try to do this, R tells me it can't find one of the columns in my csv file. It's clearly shown in the header summary. What am I doing wrong here?!
> defor=read.csv("C:\\*ommitted*\\logit_data.csv")
> head(defor)
Time Deforested Total
1 3 167 12270.15
2 6 431 12270.15
3 9 629 12270.15
4 11 974 12270.15
5 13 1611 12270.15
6 15 2279 12270.15
> summary(defor)
Time Deforested Total
Min. : 3.00 Min. : 167 Min. :12270
1st Qu.: 7.50 1st Qu.: 530 1st Qu.:12270
Median :11.00 Median : 974 Median :12270
Mean :10.43 Mean :1248 Mean :12270
3rd Qu.:14.00 3rd Qu.:1945 3rd Qu.:12270
Max. :16.00 Max. :2642 Max. :12270
> plot(Deforested/Total ~ Time)
Error in eval(expr, envir, enclos) : object 'Deforested' not found
Upvotes: 1
Views: 80
Reputation: 683
or else you can use ?attach
to add the r-object in the search path..so that you dont have to use object$Column_name
to call it. simply by Column_name
it will work.
But this is not a recommended approach for data intensive programs.
Upvotes: 1
Reputation: 13750
In the last line use
plot((defor$Deforested/defor$Total), defor$Time)
instead! Without it, R does not know what data frame to plot from. Other plotting methods like boxplot
support the ~
syntax, but plot itself is just plot(x,y)
Upvotes: 2