r - read.table, one line matrices, etc -
i'm struggling presumably simple issue cannot fix, possibly want of right keywords up...
i have following file (test.data):
th ba rb la ce nd sm eu pm 0.0813 6.049 0.5353 0.6139 1.6011 1.1892 0.3865 0.1456 v.morb 0.333 0.459 0.356 0.261 0.224 0.203 0.189
note tab-separated (not visible on screen, sorry), no trailing tabs, 1 item less in first line parsed colnames. note there missing item (second line, col. "nd"); totally empty in file (i.e. 2 successive tabs, nothing in between)
> foo<-read.table("test.data",sep="\t") > foo th ba rb la ce nd sm eu pm 0.0813 6.049 0.5353 0.6139 1.6011 1.1892 0.3865 0.1456 v.morb 0.3330 0.459 0.3560 0.2610 0.2240 na 0.2030 0.1890 > rownames(foo) [1] "pm" "v.morb" > colnames(foo) [1] "th" "ba" "rb" "la" "ce" "nd" "sm" "eu"
looks me.
now:
> y<-c(1,2,3,4) > plot(x=foo["pm",1:4],y=y) error in xy.coords(x, y, xlabel, ylabel, log) : 'x' , 'y' lengths differ
why ? probably, because
> foo["pm",1:4] th ba rb la pm 0.0813 6.049 0.5353 0.6139 > y [1] 1 2 3 4
foo , y 2 different kind of animals !
still, routinely subset , plot matrices, what's wrong foo, , how cure it?
thanks
jeff
update:
> str(foo) 'data.frame': 2 obs. of 8 variables: $ th: num 0.0813 0.333 $ ba: num 6.049 0.459 $ rb: num 0.535 0.356 $ la: num 0.614 0.261 $ ce: num 1.601 0.224 $ nd: num 1.19 0 $ sm: num 0.387 0.203 $ eu: num 0.146 0.189
update update (sorry):
> plot(x=foo[1,1:4],y=y) error in xy.coords(x, y, xlabel, ylabel, log) : 'x' , 'y' lengths differ
ok, know that.
but
> plot(x=foo[1,1:2],y=y[1:2]) > plot(x=foo[1:2,1],y=y[1:2])
both work happily. i'm lost. why foo[1,1:2] , foo[1,1:4] behave differently?
Comments
Post a Comment