I am trying the following code...
for(i in 1:bins){
print(cat(c(i, length(var1[var1==i]))))
}
Where var1 is a vector with zero or more values = {1, 2, ..., bins} (or
something like that).
The result I get is...
1 33NULL
2 28NULL
3 39NULL
4 27NULL
5 32NULL
6 30NULL
7 23NULL
8 16NULL
9 10NULL
10 15NULL
11 13NULL
12 7NULL
13 3NULL
14 7NULL
15 2NULL
16 0NULL
17 2NULL
18 0NULL
19 0NULL
20 3NULL
I don't know what I am doing to get those stray NULL characters printed.
I also tried...
for(i in 1:bins){
print(cat(i, length(var1[var1==i])))
}
Which is essentially the same.
Dan Bolser <dmb at mrc-dunn.cam.ac.uk> writes:> I am trying the following code... > > for(i in 1:bins){ > print(cat(c(i, length(var1[var1==i])))) > } > > Where var1 is a vector with zero or more values = {1, 2, ..., bins} (or > something like that). > > The result I get is... > > 1 33NULL > 2 28NULL............> 19 0NULL > 20 3NULL > > I don't know what I am doing to get those stray NULL characters printed.You're printing them, will you believe it...? Consider this:> x <- cat("abc")abc> print(x) NULL> xNULL> print(cat("abc"))abcNULL I.e. cat() always returns NULL, invisibly unless you force it to be printed. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Consider the following:
> for(i in 1:2)cat(i, "")
1 2 >
> for(i in 1:2)print(i)
[1] 1
[1] 2
> for(i in 1:2)print(cat(i))
1NULL
2NULL
hope this helps. spencer graves
Dan Bolser wrote:
>I am trying the following code...
>
>for(i in 1:bins){
> print(cat(c(i, length(var1[var1==i]))))
>}
>
>Where var1 is a vector with zero or more values = {1, 2, ..., bins} (or
>something like that).
>
>The result I get is...
>
>1 33NULL
>2 28NULL
>3 39NULL
>4 27NULL
>5 32NULL
>6 30NULL
>7 23NULL
>8 16NULL
>9 10NULL
>10 15NULL
>11 13NULL
>12 7NULL
>13 3NULL
>14 7NULL
>15 2NULL
>16 0NULL
>17 2NULL
>18 0NULL
>19 0NULL
>20 3NULL
>
>I don't know what I am doing to get those stray NULL characters printed.
>
>I also tried...
>
>for(i in 1:bins){
> print(cat(i, length(var1[var1==i])))
>}
>
>Which is essentially the same.
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
>