Error In 1/rate Non-numeric Argument To Binary Operator
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up R using diff: non-numeric argument to binary operator error up vote 2 down vote favorite We parse a CSV-File with some numbers with the following command: tt <- read.table("test2.csv",sep=";",stringsAsFactors=FALSE) And it works. Printingtt[1,] yields a nice vector and sd(tt[1,]) is sensible. However, when we try diff(tt[1,]) The command-line returns the error: Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] : non-numeric argument to binary operator error Why is that? Any ideas? r types share|improve this question asked Aug 25 '14 at 2:35 joachim 9272929 add a comment| 1 Answer 1 active oldest votes up vote 5 down vote accepted I presume that in your tt[1,], that > class(tt[1,]) # [1] "data.frame" So if you use as.numeric, you should be okay. Try this: > diff(as.numeric(tt[1,])) Here's an example that we can inspect: > tt <- data.frame(x = 1, y = 2) > is.vector(tt[1,]) # [1] FALSE > class(tt[1,]) # [1] "data.frame" > diff(tt[1,]) # Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] : # non-numeric argument to binary operator > as.numeric(tt[1,]) # [1] 1 2 > diff(as.numeric(tt[1,])) # [1] 1 share|improve this answer edited Aug 25 '14 at 2:59 answered Aug 25 '14 at 2:46 Rich Scriven 55.3k650110 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged r types or ask your own question. asked 2 yea
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community http://stackoverflow.com/questions/25478303/r-using-diff-non-numeric-argument-to-binary-operator-error of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up R: non-numeric argument to binary operator? up vote 17 down vote favorite 1 I'm attempting to create my first function in R. The function should take in a data frame, x-series from data frame, http://stackoverflow.com/questions/21560389/r-non-numeric-argument-to-binary-operator y-series from data frame, and plot a scatter plot. Seems simple enough, but I run into trouble when I attempt to check for an optional boolean argument. R Script plotScatterChart <- function(data,x,y,scale=y,line=FALSE) { require(ggplot2) data$x <- as.numeric(x) data$y <- as.numeric(y) plot <- ggplot(data, aes(x, y)) + geom_point() + # aes(alpha=0.3,color=scale) #scale_color_gradient(high="red") if(line) { plot <- plot + geom_smooth(method="lm") } ggsave(file="plot.svg", plot=plot, height=10, width=10) return(plot) } plotScatterChart(data=iris,x=iris$Petal.Length,y=iris$Petal.Width,line=TRUE) Error non-numeric argument to binary operator Extra Other suggestions for improving this function are welcome. r ggplot2 share|improve this question asked Feb 4 '14 at 18:25 Jefftopia 5801725 1 Trailing plus sign: geom_point() + –joran Feb 4 '14 at 18:27 Yep, that was a major derp on my part. –Jefftopia Feb 4 '14 at 18:44 add a comment| 2 Answers 2 active oldest votes up vote 15 down vote accepted The error is because of the trailing + after geom_point(). Remove that and it should work. share|improve this answer
Question about error of "non-numeric argument to binary operator" Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] On Tue, 2006-10-10 at 22:35 -0400, Yulei Gong wrote: > Hi, https://stat.ethz.ch/pipermail/r-help/2006-October/114741.html > I have the following data and there is no binary operator contained, > however, I still receive the error message when running unitrootTest > function, could someone give me a guidance on it?? > > >readClipboard() > [1] "245" "246" "261.5" "275.5" "307" "284.5" "289" "313.5" > "323.75" "334" " 312.5" "325" "305.5" "322.5" "317" "310.5" > [17] "302" "301" "305" "287" "277.5" "271" " 271.5" "278.5" > "279" error in "271" "263" "262" "262" "271" "262" "257" > [33] "251.5" "258" " 252.5" "254.5" "253" "251.5" "255" > "253" "253" "243" "238.5" "234" "229.5" "230.5" " 237.5" " > 235.5" > [49] "238" "225" "227.5" "233" "236.5" "236.5" "231.5" > "225" "221.5" "221.5 " "221.5" "221.5" "221.5" "221.25" "221" > "206" > [65] "207.5" "196" "192.5" "193.5" "186" " 197.5" "193.5" > "201" "195" "183" "185.5" "181.5" "179" "177" "173" error in 1/rate " > 169.5" > [81] "173" "178" "169" "173" "167" " 158.5" "169.5" > "164" "145" "127.5" "132" "131" "131" "120" "120.5" " > 120.25" > [97] "120" " 112.5" "114.5" "106" "113" "111" "113" "118.5" > "131" "131" "146.5" "133.5" "128" "132" " 130.5" "122" > [113] "122.5" "123.5" "126" "140" "132" "140" "143" > "148" "168" "162.5 " "152.5" "148" "144" "144" "150.5" > "151" > [129] "156" "156" "156" "152" "156" " 153.5" "137" > "135" "140" "135" "138.5" "139" "130" "131" "125" > "125" > [145] "121.5 " "125.5" "128" "128" "129.5" "133" "129.5" > "140" "154.5" "167.5" "156" "179" " 178.5" "174" "188" > "214" > [161] "197.5" "181.5" "181.5" "197.5" "191.5" "179" "189.5" > "184.5" "183" "182" " > 182.5" "177" "191" "198" "191" "180.5" > [177] "182" "183.5" "183" "182" " 189.5" "195" "208" > "203" "194" "176.5" "173" "173" "174" "165.5" "163" " > 162.5" > [193] "159" "162.5" "171" "168.5" "164" "158" "147" > "149" "149.5" "144" "141" " 138.5" "138" "136" "138" > "140" > [209] "135" "132.5" "130.75" "129" "129.5" "126" "127" " 128.5" > "127.5" "124" "117" "119" "120.5" "122" "129" "133" > [225] "136" "137" "133" "133" "127" "123" "122" > "117" "122" "126" "126"