Try:
dataa[subplot[,1],4]<-1
Dr. M.Sawada
Assistant Professor, GIS
University of Ottawa
Dept. Geography
P.O. Box 450 Stn. A
Ottawa, ON K1N 6N9
Tel: 613-562-5800 x1040
Fax: 613-562-5145
Eml: msawada@uottawa.ca
-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of
yves.claveau@mnr.gov.on.ca
Sent: Tuesday, December 18, 2001 9:50 AM
To: s-news@lists.biostat.wustl.edu
Subject: [S] Replacing values of one matrix from another
Replacing values of one matrix from another
Dear S-Plus users,
I am presently doing some data handling with S-Plus 6.0 under
Windows NT 4 and I am stuck with a problem. I want to replace values in
a matrix from values in a smaller one. I have:
dataa
tree dbh ht tag
1 12 7 0
2 15 9 0
3 18 12 0
4 10 5 0
5 21 14 0
and
subplot
tree tag
1 1
4 1
and I want to have
dataa
tree dbh ht tag
1 12 7 1
2 15 9 0
3 18 12 0
4 10 5 1
5 21 14 0
I thought using:
if (subplot[,1] = dataa[1,]) {dataa[,4] <- 1}
but S-Plus only uses the first line of each matrix. I then used
a less elegant solution by using the MERGE function with data frames:
datab <- merge(as.data.frame(dataa),as.data.frame(subplot),by="tree",
all.x=T)
datab$tag <- datab$tag.x+datab$tag.y
datac <- data.matrix(datab)
remove.col(datac, "tag.x",1)
remove.col(datac, "tag.y",1)
but for some strange reasons I cannot get rid of the columns
created by the merge function.
I tried an even less elegant approach by using FOR loops and IF
but I cannot get the results I want. What should I do?
Regards
Yves Claveau
-------------------------------------------
Yves Claveau, M.Sc. F.
Ontario Forest Research Institute
1235 Queen St. E.
Sault Ste Marie, ON
P6A 2E5
Ph.: (705) 946-2981 ext. 252
Fax.: (705) 946-2030
Email: yves.claveau@mnr.gov.on.ca
---------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|