Howdy, I have written a small function to generate a simple plot and my colleague is having an error when attempting to run it. Essentially I loop through categories in a data frame and take the average value for each category The categories are in $V1, subset first then mean taken and concatenated to previous values using rbind(c("label",mean(data$V6)). The result is a two-column matrix with labels in column one and values in column two. Within the function I calculate the correlation of column two and another set of values that are part of the function. On my computer (linux box running R 2.8.1) the function runs correctly. On my colleague's computer (Windows box running R 2.12) the function throws an error at the cor() function call saying that "x must be numeric." We are running on the exact same data set and source'ing the same function definition. Any help would be appreciated. - Fincher [[alternative HTML version deleted]]
Please provide a reproducible example! E.g., use ?dput to dump a minimal data.frame that exhibits this issue on the newest version of R. Justin Fincher wrote:> Howdy, > I have written a small function to generate a simple plot and my > colleague is having an error when attempting to run it. Essentially I loop > through categories in a data frame and take the average value for each > category The categories are in $V1, subset first then mean taken and > concatenated to previous values using rbind(c("label",mean(data$V6)). The > result is a two-column matrix with labels in column one and values in column > two. Within the function I calculate the correlation of column two and > another set of values that are part of the function. On my computer (linux > box running R 2.8.1) the function runs correctly. On my colleague's > computer (Windows box running R 2.12) the function throws an error at the > cor() function call saying that "x must be numeric." We are running on the > exact same data set and source'ing the same function definition. Any help > would be appreciated. > > - Fincher > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi Fincher, cor() only works on numeric arguments now (as of R 2.11 or 2.10 if memory serves). So, I would update your function to ensure that you are only passing numeric data to cor() and the error should go away (it will probably be easier on you if you can update your version of R to the latest and greatest...quite a bit has changed since 2.8.1). If you post a reproducible example of your function, I'm sure we can help update it. Cheers, Josh On Mon, Dec 13, 2010 at 1:56 PM, Justin Fincher <fincher at cs.fsu.edu> wrote:> Howdy, > ? I have written a small function to generate a simple plot and my > colleague is having an error when attempting to run it. ?Essentially I loop > through categories in a data frame and take the average value for each > category The categories are in $V1, subset first then mean taken and > concatenated to previous values using rbind(c("label",mean(data$V6)). ?The > result is a two-column matrix with labels in column one and values in column > two. ?Within the function I calculate the correlation of column two and > another set of values that are part of the function. ?On my computer (linux > box running R 2.8.1) the function runs correctly. ?On my colleague's > computer (Windows box running R 2.12) the function throws an error at the > cor() function call saying that "x must be numeric." ?We are running on the > exact same data set and source'ing the same function definition. ?Any help > would be appreciated. > > - Fincher > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
Maybe Matching Threads
- adding hyperlinked text to pdf plot
- Creating a simple 1-row heatmap
- Force printing of excluded axis annotations
- plotting lines when data has missing/NA values
- how to determine/assign a numeric vector to "Y" in the cor.test function for spearman's correlations?