[R] How to create a new data.frame based on calculation of subsets of an existing data.frame
Ivan Krylov
kry|ov@r00t @end|ng |rom gm@||@com
Tue Dec 17 22:00:02 CET 2019
Hello Ioanna!
Please don't post the same question 4 times in a row. One is just
enough; you can see it posted successfully in the R-help archives:
https://stat.ethz.ch/pipermail/r-help/2019-December/465108.html
On Tue, 17 Dec 2019 19:38:02 +0000
Ioanna Ioannou <ii54250 using msn.com> wrote:
> VC <- 0.01*( subset(D, IM.type == 'PGA' & Damage.state == 'DS1' &
> Taxonomy == 'ER+ETR_H1')[10:13] -
>
> subset(D, IM.type == 'PGA' & Damage.state == 'DS2' &
> Taxonomy == 'ER+ETR_H1')[10:13]) +
>
> 0.02*( subset(D, IM.type == 'PGA' & Damage.state == 'DS2' &
> Taxonomy == 'ER+ETR_H1')[10:13] -
>
> subset(D, IM.type == 'PGA' & Damage.state == 'DS3' &
> Taxonomy == 'ER+ETR_H1')[10:13]) +
>
> 0.43*( subset(D, IM.type == 'PGA' & Damage.state == 'DS3' &
> Taxonomy == 'ER+ETR_H1')[10:13] -
>
> subset(D, IM.type == 'PGA' & Damage.state == 'DS4' &
> Taxonomy == 'ER+ETR_H1')[10:13]) +
>
> 1.0*( subset(D, IM.type == 'PGA' & Damage.state == 'DS4' & Taxonomy
> == 'ER+ETR_H1')[10:13])
If this is supposed to be VC_1 ... VC_4, one way to make a data.frame
of it is: as.data.frame(as.list(setNames(VC, paste0('VC_', 1:4))))
(Though it's not the most elegant way, I'll have to admit.) Use cbind()
to add more columns to the resulting data.frame. Note that this
representation of the data might be not very effective to work with.
> So the question is how can I do that in an automated way for all
> possible combinations
What are "all possible combinations" here?
--
Best regards,
Ivan
More information about the R-help
mailing list