[R] Data frames
Josef Eschgfaeller
esg at felix.unife.it
Mon Apr 25 11:02:49 CEST 2005
I have two questions about data frames:
(1) How can one extract a simple matrix
from a data frame? I tried
Matrixfromdf = function (frame,without=1)
{a=frame[colnames(frame)[-without]]
v=unlist(a,use.names=F)
matrix(v,ncol=ncol(a))}
but it works well only for without=1,
perhaps also because the function in (2)
gives probably a different meaning to
the first column.
(2) How does one define a void data frame
with only column names but no values?
I tried this indirect way:
# Void df with titles from ...
Newvoid = function (...)
{a=c(...); m=length(a)
titles=paste(a,collapse=' ')
conn=textConnection(titles)
tab=read.table(conn,header=T)
close(conn); tab}
Thanks
Josef Eschgfäller
--
Josef Eschgfäller
Dipartimento Matematico
Universita' di Ferrara
http://felix.unife.it
More information about the R-help
mailing list