s-news
[Top] [All Lists]

Re: Problem copying column id's and data to new files.

To: "c.rejwan" <c.rejwan@fisheries.ubc.ca>
Subject: Re: Problem copying column id's and data to new files.
From: Chuck Cleland <ccleland@optonline.net>
Date: Tue, 09 May 2006 04:57:14 -0400
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <004501c6733e$432eb960$6401a8c0@Aurora>
References: <004501c6733e$432eb960$6401a8c0@Aurora>
User-agent: Thunderbird 1.5.0.2 (Windows/20060308)
c.rejwan wrote:
Dear Splus users,

I hope someone can help me with the following simple (I’m a beginner Splus user) problem: I want to move a subset of rows from one dataset into a new dataset, AND I would also like to copy each of the column names to the new dataset (I want to make the column names identical between the two datasets). I am using windows version 6.0 Professional release 1. I have been unable to eliminate the error message that results from my attempts to accomplish these goals. I would be very grateful for any help you can give me with this. My program, and the error message are listed below.

Note: Reachdata is my ‘real data’ file, datac is the randomized ‘real data’, and I wish to divide the datac file into two by puting 22 rows from the datac file in the file: data2, while leaving the remaining rows in data1.

Why not do it like this:

datac <- data.frame(A=runif(216), B=runif(216), C=runif(216), D=runif(216), E=runif(216))

rsamp22 <- sample(1:216, size=22)
data1 <- datac[-rsamp22,]
data2 <- datac[rsamp22,]

MY PROGRAM:

rm(datac)
rm(data2)

datac<-Reachdatcc
data2<-datac
data2 <- gui.remove.row(target = data2, target.row.spec = list(1:216))

# Note that I am removing all of the data (there were 216 rows in the file: data2). This is the only # way that I know of, for obtaining an empty data file with the column titles/identifications intact.

data1 <<- sample(datac, replace=FALSE)

data2 <- gui.move.row(target = data2, source = data1, source.row.spec = list(1:22), overwrite = F)

THE ERROR MESSAGE:
...

datac <- data.frame(A=runif(216), B=runif(216), C=runif(216), D=runif(216), E=runif(216))

data2 <- datac[-c(1:216),]

> dim(data2)
[1] 0 5

> names(data2)
[1] "A" "B" "C" "D" "E"

# This just put columns in random order - not sure why you need it
data1 <- sample(datac, replace=FALSE)

data2 <- gui.move.row(target = data2, source = data1, source.row.spec = list(1:22), overwrite = F)

hope this helps,

Chuck

--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

<Prev in Thread] Current Thread [Next in Thread>