[R] Copying rows in data frames

arun smartpink111 at yahoo.com
Tue Mar 19 14:10:28 CET 2013



Hi,
In your original message, you were trying to copy the colnames of df1.  I am not sure that is what you wanted.  Also, there were some spaces between the columns, which I had to delete.

This is how your dataset looks like now:

dat1<-read.csv("dataSahana1.csv",sep="\t",header=TRUE,stringsAsFactors=FALSE)
str(dat1)
#'data.frame':    4625 obs. of  21 variables:
# $ GENE: chr  "amt:Amet_0001" "amt:Amet_0002" "amt:Amet_0003" "amt:Amet_0004" ...
# $ A   : int  29 19 1 13 7 42 44 4 6 13 ...
# $ C   : int  0 3 0 0 1 2 2 1 3 1 ...
# $ D   : int  23 15 4 18 2 30 60 5 13 16 ...
# $ E   : int  34 42 6 29 9 65 77 12 11 30 ...
# $ F   : int  17 12 1 10 5 19 16 4 5 12 ...
# $ G   : int  16 18 9 22 4 59 58 7 10 7 ...
# $ H   : int  12 8 0 8 4 11 17 0 1 4 ...
# $ I   : int  42 35 9 32 12 53 88 14 20 21 ...
# $ K   : int  29 25 10 38 11 44 71 13 16 28 ...
# $ L   : int  39 43 9 50 8 51 75 13 6 24 ...
# $ M   : int  6 7 1 6 1 16 27 3 5 12 ...
# $ N   : int  35 26 3 26 2 27 40 5 9 19 ...
# $ P   : int  20 13 1 8 4 16 22 1 4 4 ...
# $ Q   : int  13 9 3 21 2 24 21 4 1 10 ...
# $ R   : int  25 14 2 19 4 36 49 2 2 17 ...
# $ S   : int  34 21 1 12 9 28 37 4 7 14 ...
# $ T   : int  27 20 0 12 4 41 43 5 10 11 ...
# $ V   : int  32 30 8 28 4 42 60 5 10 13 ...
# $ W   : int  3 0 0 1 0 1 0 1 0 1 ...
# $ Y   : int  12 8 1 15 2 28 23 2 2 9 ...
 dat1[1:3,]
#           GENE  A C  D  E  F  G  H  I  K  L M  N  P  Q  R  S  T  V W  Y
#1 amt:Amet_0001 29 0 23 34 17 16 12 42 29 39 6 35 20 13 25 34 27 32 3 12
#2 amt:Amet_0002 19 3 15 42 12 18  8 35 25 43 7 26 13  9 14 21 20 30 0  8
#3 amt:Amet_0003  1 0  4  6  1  9  0  9 10  9 1  3  1  3  2  1  0  8 0  1
 dat2<- data.frame(matrix(NA,ncol=20,nrow=5))
 dat2[1,]<-dat1[1,-1]
dat2[1,]
#  X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20
#1 29  0 23 34 17 16 12 42 29  39   6  35  20  13  25  34  27  32   3  12
#If you wanted the colnames of dat1
dat2[1,]<- colnames(dat1)[-1]
 dat2[1,]
#  X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20
#1  A  C  D  E  F  G  H  I  K   L   M   N   P   Q   R   S   T   V   W   Y

A.K.




________________________________
From: Sahana Srinivasan <sahanasrinivasan.91 at gmail.com>
To: arun <smartpink111 at yahoo.com> 
Sent: Tuesday, March 19, 2013 8:42 AM
Subject: Re: [R] Copying rows in data frames


This is the file I am reading in. The dput() command keeps getting truncated, and I thought it might be easier to go straight to the bottom of this.


Sorry about being so unwieldy, R is new to m and a lot more confusing than I thought.




On Tue, Mar 19, 2013 at 12:37 PM, arun <smartpink111 at yahoo.com> wrote:

Could you subset your whole dataset to 10 rows and 10 columns etc.... 
>dput(df2[1:10,1:10])
>
>
>
>
>
>
>
>________________________________
>From: Sahana Srinivasan <sahanasrinivasan.91 at gmail.com>
>To: arun <smartpink111 at yahoo.com>
>Sent: Tuesday, March 19, 2013 8:32 AM
>
>Subject: Re: [R] Copying rows in data frames
>
>
>
>The whole thing does not show when I print it on the console. It's essentially "amt : Amet_0001" till 4802.
>



More information about the R-help mailing list