R: read.table problems - r

I might just be crazy but I really can't see where I am going wrong on my simple R program. I am trying to read a table from a file but every time I try to it comes back with this error:
./tmp.r: line 1: syntax error near unexpected token `('
./tmp.r: line 1: `tmp <- read.table("/home/Data/run1.DOC.sample_summary",header=FALSE)'
The file I am trying to read from looks something like this:
Aim A_%_above_20 A_%_above_30 A_%_above_40
28 0.0 0.0 0.0
99 50 100.0 82.9
34 62.1 0.0 0.0
Here is my code:
tmp <- read.table("/home/Data/run1.DOC.sample_summary",header=FALSE)
names(tmp)
max_num <- max(tmp)
hist(tmp$'*_%_above_30',col=heat.colors(max_num), main='Percent in Test', xlab='Percent Covered')
Does anyone see what I am doing wrong here? I am just not seeing it.
Thanks

Those tmp$'*_%_above_30' really work in your last line ?
Also, try to put comments on different part of your code to see which one is making your code crash.
Finally, maybe it's just a bad encoding of some characters in your code. Try to rewrite it from scratch.
And how do you launch your script ?

it this because you used wrong path name? e.g., try changing "home..." to "/home..."

Related

Can anyone tell me why R is giving me two different answers for this code?

I have this code that takes a response from a specific cell in my excel sheet:
if (data$response.keys[215] == 's'){
selection <- 0
}else{
selection <- 1
}
It gives the correct information. However, when I was messing around with something and wrote it using the data$, it tells me that the information is in 163 and not 215.
which(data$response.keys == 's')
output: 163L
I also found that if I plug 163 into the top code instead of 215 it still gives me the correct answer. I was just wondering why this happens even though it doesn't appear to actually be causing any problems.

Unexpected Coding Error on Arduino Uno R3

When I run this code it gives me an error, I am still a beginner so I don't know how to fix it.
This is what I have written so far
Giving a look in your code, you missed to place some semicolons (;) at the end of some instructions, to be more specific you miss them in lines:
5
32
34
37
40
In line 9, you have to type "Serial.begin(9600);" instead "serial.begin(9600);"
On the last else, you forgot to enclose the instructions between "{}" and placing the '}' to close the void loop.
You are making reference to a routine named getVoltage, but I don't see it
Another issue that I can see is that you have to write with uppercase words like: OUTPUT, INPUT, HIGH and LOW
Please share more details once you be able to fix this observations

Error in source() unexpected numeric constant

when I write an R script in a test.R file
nb <- 22
paste("Etudions le nombre: ",nb)
paste("Le logarithme népérien de ce nombre est: ", log(nb))
paste("La racine carrée de ce nombre est: ", sqrt(nb))
paste("Le cosinus de ce nombre est: ", cos(nb))
paste("Si on ajoute 3 au nombre ", nb, " on obtient: ", nb + 3)
q("ask")
I executed using :
source("/Users/shous/Desktop/Master2.0/LanguageR/test.R")
error message :
Error in source("/Users/shous/Desktop/Master2.0/LanguageR/test.R") :
/Users/shous/Desktop/Master2.0/LanguageR/test.R:1:9: unexpected numeric constant
1: nb <- 22
It can be encoding problem: unexpected numeric constant 1: nb <- 22
I guess you don't want to have this character Â.Try to change file encoding or rewrite problematic line (not copy paste).
unexpected numeric constant 1: nb <- 22
This is R telling you that it found the line
nb <- 22
and that isn't valid syntax. You can duplicate this simply on the command line with something like a = a 22, which also isn't valid syntax. You need to correct that line of code - I don't know what you want it to be, perhaps there is a missing line break, or perhaps it should be  + 22 or Â[22], etc...
The line that produces the error does not occur in the code you show, perhaps you should make sure you are running the right file.

readHTMLTable does not recognize URL

Okay guys, I have, what I'm sure, is an entry-level problem. Still, I cannot explain it. Here's my code and its error:
> sample1 = readHTMLTable(http://www.pro-football-reference.com/boxscores/201609150buf.htm, which = 16)
Error: unexpected '/' in "sample1 = readHTMLTable(http:/"
It's having a problem with the second front-slash? Not only does every URL have two front-slashes, but I've poured through countless examples of this function, both on this site and others, and they've all formatted this code in this way. So, what am I doing wrong?
Additionally, I've tried it without the back-slashes:
> sample1 = readHTMLTable(www.pro-football-reference.com/boxscores/201609150buf.htm, which = 16)
Error: unexpected symbol in "sample1 = readHTMLTable(www.pro-football-reference.com/boxscores/201609150buf.htm"
Here, I'm not even sure which symbol it's talking about.
Please explain.
The issue is that you need to place your url in quotes (""). The following does return the table from your specified url:
sample1 = readHTMLTable("www.pro-football-reference.com/boxscores/201609150buf.htm")
As you probably know, the "which=" parameter is used to select which of the tables in that page you would like to retrieve. However my own attempts show that only 1 and 2 work. Could you tell me which table you are attempted to read into R? If this method doesn't end up working you can also attempt to read in the entirety of the webpage and parse out the table in question.
Hope this helps get things started!

Error reported on a blank line

I am truly stumped this afternoon and have done quite a bit of searching to no avail. I am getting the error
"Object doesn't support this property or method /admin/Upload1_20120508JB.asp, line 91"
From the following code:
90 wf = fso2.CreateTextFile(sWriteFilePath)
91
92 If fso1.FileExists(sReadFilePath) Then ...
Line 91 is blank and Line 90 works as expected, the file gets created in the proper location. Has anyone seen anything like this before? If so, what was the solution?
Thanks!
You must use Set, when you assign an object to a variable.
(see here to realize that today is a bad day for this feature of VBScript.)

Resources