[R] Change in how R handles assignments?
David Kreil
kreil at ebi.ac.uk
Mon May 17 16:07:59 CEST 2004
Dear R-users and experts,
I have been using the following code in earlier versions of R:
q[,names(info)]<-info[no,];
with
> class(info)
[1] "data.frame"
> class(q)
[1] "data.frame"
> dim(q)
[1] 7488 68
> dim(info)
[1] 12 8
> dim(info[no,])
[1] 1 8
The column names(info) did not exist in q before the assignment.
What used to happen (as intended) was that they would be created, and each of
the 7488 rows would be set the same value, info[no,].
Now, in the current version of R this gives the error:
Error in "[[<-.data.frame"(`*tmp*`, k, value = rep(value[[k]], len = n)) :
replacement has 7488 rows, data has 1
I can use the following as a workaround
for (n in names(info))
q[,n]<-info[no,n];
but it seems clunky. Is there a more elegant/simple way to do the same thing
in the current version of R? It seems I'm unintentionally forcing it to do
something it doesn't "like".
Comments much appreciated.
Best regards,
David.
------------------------------------------------------------------------
Dr David Philip Kreil ("`-''-/").___..--''"`-._
Research Fellow `6_ 6 ) `-. ( ).`-.__.`)
University of Cambridge (_Y_.)' ._ ) `._ `. ``-..-'
++44 1223 764107, fax 333992 _..`--'_..-_/ /--'_.' ,'
www.inference.phy.cam.ac.uk/dpk20 (il),-'' (li),' ((!.-'
More information about the R-help
mailing list