Hello, all. I'm new to R and just beginning to learn to write functions. I
know I'm out of my depth posting here, and I'm sure my issue is mundane.
But here goes. I'm analyzing the American National Election Study (nes),
looking at mean values of a numeric dep_var (environ.therm) across values
of a factor (partyid3). I use ddply from plyr and wtd.mean from Hmisc. The
nes requires a weight var (wt). I use Rcmdr's plotMeans to obtain a line
chart. The following code works:

attach(nes)
obj1 = ddply(nes, .(partyid3), summarise,
  var = wtd.mean(environ.therm, wt))
print(obj1)
plotMeans(obj1$var, obj1$partyid3, error.bars="none")

Here is what happens when I write and run the function, meanN:
 meanN=function(data,x,y,w=NULL)
+  {obj1=ddply(data,.(x),summarise, var=wtd.mean(y,w))
+  print(obj1)
+  plotMeans(obj1$var, obj1$x, error.bars="none")
+ }
 meanN(nes,partyid3,environ.therm,wt)
Error in wtd.mean(y, w) : object 'w' not found

I have assigned data, x, y, and w. I'm just learning this powerful stuff.
Any help would be greatly appreciated.

Hutch Pollock

	[[alternative HTML version deleted]]

