Use indices.
Eg:
# a sample dataframe
lupepn1 <- data.frame(
bushno=rep(1:2,4),
bout=rep(1:4,each=2),
survival=rep(0,8),
wwg=rep(1,8)
)
lupepn1
# select the wrong cases
wrong <- lupepn1$bushno==1 & lupepn1$bout %in% c(1,2)
# make a replacement frame
replacement <- rbind(c(4,5),c(9,10))
# do the replacement
lupepn1[wrong,c("survival","wwg")] <- replacement
lupepn1
Cheers
Joris
On Wed, Jun 9, 2010 at 3:36 AM, Mr. Natural <drstrong at ucdavis.edu>
wrote:>
> Thanks for the excellent help on my recent question on this topic in which
> the data frame had been reshaped by cast.
> Now, I would like to access and change erroneous data in a data frame that
> has not been reshaped.
>
> The file is lupepn1, with identifier variables bushno & bout and
> dependent variables survival, and wwG
> I know the bushno and bout of the erroneous dependent survival and wwG
data.
> I could correct these in the csv file before read.data, but I would like to
> learn some more R
>
> head(lupepn1)
> ?bushno bout survival wwG
> 2 ? ? ?1 ? ?2 ? ? ? ?0 ? 0
> 3 ? ? ?1 ? ?3 ? ? ? ?0 ? 0
> 4 ? ? ?1 ? ?4 ? ? ? ?0 ? 0
> 5 ? ? ?1 ? ?5 ? ? ? ?0 ? 0
> 6 ? ? ?1 ? ?6 ? ? ? ?0 ? 2
> 7 ? ? ?1 ? ?7 ? ? ? ?0 ? 0
>
>> str(lupepn1)
> 'data.frame': ? 5023 obs. of ?4 variables:
> ?$ bushno ?: int ?1 1 1 1 1 1 1 2 2 2 ...
> ?$ bout ? ?: int ?2 3 4 5 6 7 8 1 2 3 ...
> ?$ survival: int ?0 0 0 0 0 0 0 1 1 1 ...
> ?$ wwG ? ? : int ?0 0 0 0 2 0 0 5 1 0 ...
> ?- attr(*, "na.action")=Class 'omit' ?Named int [1:81] 1
49 65 177 201 257
> 337 417 449 505 ...
> ?.. ..- attr(*, "names")= chr [1:81] "1" "49"
"65" "177" ...
>
> Your kind advice is very much appreciated.
> Mr. Natural.
>
>>
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/correcting-a-few-data-in-an-unreshaped-data-frame-tp2248219p2248219.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>
--
Joris Meys
Statistical consultant
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control
tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php