Hi,
set.seed(25)
?df1<- as.data.frame(matrix(sample(LETTERS[1:10],20,replace=TRUE),ncol=5),stringsAsFactors=FALSE)
?df1
#? V1 V2 V3 V4 V5
#1? E? B? A? J? F
#2? G? J? C? F? H
#3? B? G? D? G? E
#4? I? D? D? B? H
?str(df1)
#'data.frame':??? 4 obs. of? 5 variables:
# $ V1: chr? "E" "G" "B" "I"
# $ V2: chr? "B" "J" "G" "D"
# $ V3: chr? "A" "C" "D" "D"
# $ V4: chr? "J" "F" "G" "B"
# $ V5: chr? "F" "H" "E" "H"
?df2<-as.data.frame(matrix(NA,ncol=5,nrow=3))
?df2[1,]<-df1[1,]
?df2[1,]
#? V1 V2 V3 V4 V5
#1? E? B? A? J? F
A.K.
----- Original Message -----
From: Sahana Srinivasan <sahanasrinivasan.91 at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Tuesday, March 19, 2013 7:55 AM
Subject: [R] Copying rows in data frames
Hi,
I'm trying to copy the first row of one data frame to another. This is the
statement I am using :
df2[1,]<-df1[1,];
I have printed them out separately:
df1[1,] = A C D E F
But after copying:
df2[1,] = 96 29 88 122 68
Why isn't it copying? They are both data frames, and "as.character" isn't
working either.
Thanks for your input :)
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.