melissa moore
2012-Oct-17 15:21 UTC
[R] In mean.default(X[[50L]], ...) : argument is not numeric or logical: returning NA
Hi Arun, Thank you so much for your help. In the end, I wound up using: sp.data$spores<-as.numeric(as.character(sp.data$spores)) The stats guy on campus helped me :) Be well, Melissa ________________________________________ From: arun kirshna [via R] [ml-node+s789695n4646457h12@n4.nabble.com] Sent: Wednesday, October 17, 2012 6:51 AM To: Moore, Melissa Subject: Re: In mean.default(X[[50L]], ...) : argument is not numeric or logical: returning NA HI, Try this: set.seed(1) sp.data<-data.frame(iso=factor(rep(1:4,each=4)),spec=factor(sample(1:5,16,replace=TRUE)),temp=factor(rep(c(28,30,32,34),each=4)),site=factor(sample(1:6,16,replace=TRUE)),spores=factor(sample(1:50,16,replace=FALSE))) ave.sp <- aggregate(sp.data$spores, by=list(iso=sp.data$iso, spec=sp.data$spec, temp=sp.data$temp, site=sp.data$site), FUN=mean, na.rm=T) # In mean.default(X[[15L]], ...) : #argument is not numeric or logical: returning NA sp.data1<-within(sp.data,{spores<-as.numeric(as.character(spores))}) str(sp.data1) #'data.frame': 16 obs. of 5 variables: # $ iso : Factor w/ 4 levels "1","2","3","4": 1 1 1 1 2 2 2 2 3 3 ... # $ spec : Factor w/ 5 levels "1","2","3","4",..: 2 2 3 5 2 5 5 4 4 1 ... # $ temp : Factor w/ 4 levels "28","30","32",..: 1 1 1 1 2 2 2 2 3 3 ... # $ site : Factor w/ 6 levels "1","2","3","4",..: 5 6 3 5 6 2 4 1 2 3 ... # $ spores: num 25 10 40 32 37 5 47 18 35 27 ... ave.sp1 <- aggregate(sp.data1$spores, by=list(iso=sp.data1$iso, spec=sp.data1$spec, temp=sp.data1$temp, site=sp.data1$site), FUN=mean, na.rm=T) head(ave.sp1) # iso spec temp site x #1 2 4 30 1 18.0 #2 3 2 32 1 44.0 #3 2 5 30 2 5.0 #4 3 4 32 2 35.0 #5 1 3 28 3 40.0 #6 3 1 32 3 24.5 A.K. ________________________________ If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/In-mean-default-X-50L-argument-is-not-numeric-or-logical-returning-NA-tp4646425p4646457.html To unsubscribe from In mean.default(X[[50L]], ...) : argument is not numeric or logical: returning NA, click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4646425&code=bWVsaXNzYS5tb29yZUB1bWNvbm5lY3QudW10LmVkdXw0NjQ2NDI1fDUxMTM2Nzc2Ng==>. NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> -- View this message in context: http://r.789695.n4.nabble.com/In-mean-default-X-50L-argument-is-not-numeric-or-logical-returning-NA-tp4646425p4646475.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]