Re: [R] How to save output of multiple loops in a matrix

2020-03-21 Thread Ioanna Ioannou
nlist(str_split(as.character(d1[calc_rows & 
DS3_rows,]$Y_vals), pattern = ","))) -
  as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS4_rows,]$Y_vals), pattern = "," +
  D2L[5]*as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS4_rows,]$Y_vals), pattern = ",")))
print(VC[calc_rows] )
  }
}
  }



Vul <- distinct(d1[,c(1,2)])

dim(VC) <- c(length(unlist(str_split(as.character(d1[2,]$Y_vals), pattern = 
","))),length(distinct(d1[,c(1,2)])$Name))  ## (rows, cols)
VC
VC_t <- t(VC)
Vulnerability <- matrix(apply(VC_t, 1, function(x) paste(x, collapse = ',')))

Vul$Y_vals <- Vulnerability




____
From: Jeff Newmiller 
Sent: 21 March 2020 16:27
To: r-help@r-project.org ; Ioanna Ioannou 
; r-help@r-project.org 
Subject: Re: [R] How to save output of multiple loops in a matrix

You have again posted using HTML  and the result is unreadable. Please post a 
reproducible example using dput instead of assuming we can read your formatted 
code or table.

On March 21, 2020 8:59:58 AM PDT, Ioanna Ioannou  wrote:
>Hello everyone,
>
>I am having this data.frame. For each row you have 26 values aggregated
>in a cell and separated by a comma. I want to do some calculations for
>all unique names and taxonomy which include the four different damage
>states. I can estimate the results but i am struggling to save them in
>a data.frame and assign next to them the unique combination of the
>name, taxonomy. Any help much appreciated.
>
>
>d1 <- read.csv('test.csv')
>
>D2L <- c(0, 2, 10, 50, 100)
>
>VC_final <- array(NA, length(distinct(d1[,c(65,4,3)])$Name) )
>VC   <- matrix(NA,
>length(distinct(d1[,c(65,4,3)])$Name),length(unlist(str_split(as.character(d1[1,]$Y_vals),
>pattern = ","
>
># get the rows for the four damage states
>DS1_rows <- d1$Damage_State ==  unique(d1$Damage_State)[4]
>DS2_rows <- d1$Damage_State ==  unique(d1$Damage_State)[3]
>DS3_rows <- d1$Damage_State ==  unique(d1$Damage_State)[2]
>DS4_rows <- d1$Damage_State ==  unique(d1$Damage_State)[1]
>
># step through all possible values of IM.type and Taxonomy and Name
> This is true for this subset not generalibale needs to be checked
>first ##
>
>for(IM in unique(d1$IM_type)) {
>  for(Tax in unique(d1$Taxonomy)) {
>for(Name in unique(d1$Name)) {
>   # get a logical vector of the rows to be use DS5 in this calculation
>   calc_rows <- d1$IM_type == IM & d1$Taxonomy == Tax & d1$Name == Name
>
>
>  # check that there are any such rows in the DS5ata frame
>  if(sum(calc_rows)) {
>cat(IM,Tax,Name,"\n")
># if so, fill in the four values for these rows
>VC[calc_rows]  <- D2L[1] * (1-
>as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS1_rows,]$Y_vals), pattern = ","))) ) +
>D2L[2]* (as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS1_rows,]$Y_vals), pattern = ","))) -
>as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS2_rows,]$Y_vals), pattern = "," +
>D2L[3]* (as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS2_rows,]$Y_vals), pattern = ","))) -
>as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS3_rows,]$Y_vals), pattern = "," +
>D2L[4] * (as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS3_rows,]$Y_vals), pattern = ","))) -
>as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS4_rows,]$Y_vals), pattern = "," +
>D2L[5]*as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS4_rows,]$Y_vals), pattern = ",")))
>print(VC[calc_rows] )
>  }
>}
>  }
>}
>
>  for(Tax in unique(d1$Taxonomy)) {
>for(Name in unique(d1$Name)) {
>   # get a logical vector of the rows to be use DS5 in this calculation
>   calc_rows <- d1$IM_type == IM & d1$Taxonomy == Tax & d1$Name == Name
>
>
>  # check that there are any such rows in the DS5ata frame
>  if(sum(calc_rows)) {
>cat(IM,Tax,Name,"\n")
># if so, fill in the four values for these rows
>VC[calc_rows]  <- D2L[1] * (1-
>as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS1_rows,]$Y_vals), pattern = ","))) ) +
>D2L[2]* (as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS1_rows,]$Y_vals), pattern = ","))) -
>as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS2_rows,]$Y_vals), pattern = "," +
>D2L[3]* (as.numeric(unlist(str_split(as.character(d1[calc_rows &
>DS2_rows,]$Y_vals), pattern = ","))) -

[R] How to save output of multiple loops in a matrix

2020-03-21 Thread Ioanna Ioannou
Hello everyone,

I am having this data.frame. For each row you have 26 values aggregated in a 
cell and separated by a comma. I want to do some calculations for all unique 
names and taxonomy which include the four different damage states. I can 
estimate the results but i am struggling to save them in a data.frame and 
assign next to them the unique combination of the name, taxonomy. Any help much 
appreciated.


d1 <- read.csv('test.csv')

D2L <- c(0, 2, 10, 50, 100)

VC_final <- array(NA, length(distinct(d1[,c(65,4,3)])$Name) )
VC   <- matrix(NA, 
length(distinct(d1[,c(65,4,3)])$Name),length(unlist(str_split(as.character(d1[1,]$Y_vals),
 pattern = ","

# get the rows for the four damage states
DS1_rows <- d1$Damage_State ==  unique(d1$Damage_State)[4]
DS2_rows <- d1$Damage_State ==  unique(d1$Damage_State)[3]
DS3_rows <- d1$Damage_State ==  unique(d1$Damage_State)[2]
DS4_rows <- d1$Damage_State ==  unique(d1$Damage_State)[1]

# step through all possible values of IM.type and Taxonomy and Name
 This is true for this subset not generalibale needs to be checked first ##

for(IM in unique(d1$IM_type)) {
  for(Tax in unique(d1$Taxonomy)) {
for(Name in unique(d1$Name)) {
  # get a logical vector of the rows to be use DS5 in this calculation
  calc_rows <- d1$IM_type == IM & d1$Taxonomy == Tax & d1$Name == Name


  # check that there are any such rows in the DS5ata frame
  if(sum(calc_rows)) {
cat(IM,Tax,Name,"\n")
# if so, fill in the four values for these rows
VC[calc_rows]  <- D2L[1] * (1- 
as.numeric(unlist(str_split(as.character(d1[calc_rows & DS1_rows,]$Y_vals), 
pattern = ","))) ) +
  D2L[2]* (as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS1_rows,]$Y_vals), pattern = ","))) -
 as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS2_rows,]$Y_vals), pattern = "," +
  D2L[3]* (as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS2_rows,]$Y_vals), pattern = ","))) -
 as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS3_rows,]$Y_vals), pattern = "," +
  D2L[4] * (as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS3_rows,]$Y_vals), pattern = ","))) -
  as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS4_rows,]$Y_vals), pattern = "," +
  D2L[5]*as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS4_rows,]$Y_vals), pattern = ",")))
print(VC[calc_rows] )
  }
}
  }
}

  for(Tax in unique(d1$Taxonomy)) {
for(Name in unique(d1$Name)) {
  # get a logical vector of the rows to be use DS5 in this calculation
  calc_rows <- d1$IM_type == IM & d1$Taxonomy == Tax & d1$Name == Name


  # check that there are any such rows in the DS5ata frame
  if(sum(calc_rows)) {
cat(IM,Tax,Name,"\n")
# if so, fill in the four values for these rows
VC[calc_rows]  <- D2L[1] * (1- 
as.numeric(unlist(str_split(as.character(d1[calc_rows & DS1_rows,]$Y_vals), 
pattern = ","))) ) +
  D2L[2]* (as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS1_rows,]$Y_vals), pattern = ","))) -
 as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS2_rows,]$Y_vals), pattern = "," +
  D2L[3]* (as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS2_rows,]$Y_vals), pattern = ","))) -
 as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS3_rows,]$Y_vals), pattern = "," +
  D2L[4] * (as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS3_rows,]$Y_vals), pattern = ","))) -
  as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS4_rows,]$Y_vals), pattern = "," +
  D2L[5]*as.numeric(unlist(str_split(as.character(d1[calc_rows & 
DS4_rows,]$Y_vals), pattern = ",")))
print(unique(VC ))
  }
    }
  }

Vul <- distinct(d1[,c(65,4,3)])

dim(VC) <- c(length(unlist(str_split(as.character(d1[1,]$Y_vals), pattern = 
","))),length(distinct(d1[,c(65,4,3)])$Name))  ## (rows, cols)
VC
VC_t <- t(VC)
Vulnerability <- matrix(apply(VC_t, 1, function(x) paste(x, collapse = ',')))

Vul$Y_vals <- Vulnerability




Best,
ioanna










NameTaxonomyDamage_StateY_vals
Hancilar et. al (2014) - CR/LDUAL school - Case V (Sd)  
CR/LDUAL/HEX:4+HFEX:12.8/YAPP:1990/EDU+EDU2//PLFSQ/IRRE//RSH1// Slight  
4.61e-149,0.007234459,0.158482316,0.438164341,0.671470035,0.818341464,0.901312438,0.946339742,0.970531767,0.983584997,0.990707537,0.994650876,0.996869188,0.998137671,0.998874868,0.9993101,0.999570978,0.9997296

[R] How to create a vector by searching information in multiple data.tables in r?

2020-01-31 Thread Ioanna Ioannou
Hello everyone,

Once again i am a bit stack. I have over 200 json files with information. I 
managed to manipulate them and their format is rather difficult as shown below. 
Unfortunately, not all these files contain the same fields. I want to extract 
e.g., the country from all these files. How can i add NA for the files for 
which the country is not mentioned?

Here is a reproducible example. Lets say i have two files, three files, two 
provide the country and the one does not.  essentially i want a vector called 
country which will look like this:

Country <- c('Colombia', 'Greece', NA)

Any help much appreciated!

Best,
ioanna


A<- data.frame( name1 = c('fields', 'fields', 'fields'),
  name2= c('category', 'asset', 'country'),
  value  = c('Structure Class', 'Building', 
'Colombia')



B<- data.frame( name1 = c('fields', 'fields', 'fields'),
  name2= c('category', 'asset', 'country'),
  value  = c('Structure Class', 'Building', 
'Greece')



C<- data.frame( name1 = c('fields', 'fields', 'fields'),
  name2= c('category', 'asset', 'assessment'),
  value  = c('Structure Class', 'Building', 
'Fragility')



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] How to save multiple values of a variable in a json file in R

2020-01-16 Thread Ioanna Ioannou
ok, my problem is the follwoing
a<- read_json(json_file)
a$fields$geo_applicability$fields$countries[[1]]$fields$name

this was i can see the name of a single country reported first in the json. 
HOwever, i  need to save all 59. My worry is that i have multiple files that i 
need to read and in some cases there will be one country reported and in some 
others multiple. How can i optimise the code?

Best,


From: Rainer M Krug 
Sent: 16 January 2020 14:47
To: Ioanna Ioannou 
Subject: Re: [R] How to save multiple values of a variable in a json file in R

Check the hep of the read_json() function and please keep the conversation on 
the list

On 16 Jan 2020, at 15:42, Ioanna Ioannou 
mailto:ii54...@msn.com>> wrote:

I will try the package but i could do with a worked example.


From: Rainer M Krug mailto:rai...@krugs.de>>
Sent: 16 January 2020 14:29
To: Ioanna Ioannou mailto:ii54...@msn.com>>
Subject: Re: [R] How to save multiple values of a variable in a json file in R

Have you looked at the jsonlite package?

Rainer


On 16 Jan 2020, at 15:21, Ioanna Ioannou 
mailto:ii54...@msn.com>> wrote:

hello everyone,

and happy new year!

I have this problem: I want to save the name of the 'countries', the 
'taxonomy_gem' and the 'minimum_im' and 'maximum_im' . The problem is that 
there are several names of countries.  How can i transfer the information from 
the json file to an R data.frame? See below for the json file.

Best,
ioanna



json_file<- {
   "pk": 670,
   "model": "vulnerability.generalinformation",
   "fields": {
   "category": "Structure class",
   "article_title": "A GLOBAL DATABASE OF VULNERABILITY MODELS FOR SEISMIC 
RISK ASSESSMENT",
   "name": "CR/LFINF/DUL/H:2",
   "publication_conference_name": "16EECE",
   "llrs": null,
   "material": null,
   "web_link": "",
   "owner": {
   "pk": 1900,
   "model": "people.profile",
   "fields": {
   "username": "lmartins",
   "first_name": "",
   "last_name": "",
   "email": 
"luis.mart...@globalquakemodel.org<mailto:luis.mart...@globalquakemodel.org>"
   }
   },
   "general_comments": "",
   "geo_applicability": {
   "pk": 669,
   "model": "vulnerability.geoapplicability",
   "fields": {
   "general_information": 670,
   "area": "",
   "countries": [
   {
   "pk": "CIV",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "Cte d'Ivoire"
   }
   },
   {
   "pk": "CMR",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "Cameroon"
   }
   },
   {
   "pk": "SDN",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "Sudan"
   }
   },
   {
   "pk": "SSD",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "South Sudan"
   }
   },
   {
   "pk": "TUN",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "

[R] How to save multiple values of a variable in a json file in R

2020-01-16 Thread Ioanna Ioannou
hello everyone,

and happy new year!

I have this problem: I want to save the name of the 'countries', the 
'taxonomy_gem' and the 'minimum_im' and 'maximum_im' . The problem is that 
there are several names of countries.  How can i transfer the information from 
the json file to an R data.frame? See below for the json file.

Best,
ioanna



{
"pk": 670,
"model": "vulnerability.generalinformation",
"fields": {
"category": "Structure class",
"article_title": "A GLOBAL DATABASE OF VULNERABILITY MODELS FOR SEISMIC 
RISK ASSESSMENT",
"name": "CR/LFINF/DUL/H:2",
"publication_conference_name": "16EECE",
"llrs": null,
"material": null,
"web_link": "",
"owner": {
"pk": 1900,
"model": "people.profile",
"fields": {
"username": "lmartins",
"first_name": "",
"last_name": "",
"email": "luis.mart...@globalquakemodel.org"
}
},
"general_comments": "",
"geo_applicability": {
"pk": 669,
"model": "vulnerability.geoapplicability",
"fields": {
"general_information": 670,
"area": "",
"countries": [
{
"pk": "CIV",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Cte d'Ivoire"
}
},
{
"pk": "CMR",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Cameroon"
}
},
{
"pk": "SDN",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Sudan"
}
},
{
"pk": "SSD",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "South Sudan"
}
},
{
"pk": "TUN",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Tunisia"
}
},
{
"pk": "TGO",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Togo"
}
},
{
"pk": "ZAF",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "South Africa"
}
},
{
"pk": "NER",
"model": "vulnerability.country",
"fields": {
  

Re: [R] How to create a new data.frame based on calculation of subsets of an existing data.frame

2019-12-21 Thread Ioannou, Ioanna
Hello Jim , 

Thank you ever so much for your help. I was truly stuck! 

This looks much better and yes I can turn them into a matrix no problem. Indeed 
I need only the results for ER+ETR_H1,PGA and ER+ETR_H2,Sa. One minor point as 
it is the VC has 4 values for three cases instead of the aforementioned two. In 
fact, the third is identical to the first. Could you please optimize? 

Thank you very much again, 
Best, 
ioanna

-Original Message-
From: Jim Lemon [mailto:drjimle...@gmail.com] 
Sent: Friday, December 20, 2019 9:04 PM
To: Ioannou, Ioanna 
Cc: r-help mailing list 
Subject: Re: [R] How to create a new data.frame based on calculation of subsets 
of an existing data.frame

Hi Ioanna,
We're getting somewhere, but there are four unique combinations  of Taxonomy 
and IM.type:

ER+ETR_H1,PGA
ER+ETR_H2,PGA
ER+ETR_H1,Sa
ER+ETR_H2,Sa

Perhaps you mean that ER+ETR_H1 only occurs with PGA and ER+ETR_H2 only occurs 
with Sa. I handled that by checking that there were any rows that corresponded 
to the condition requested.

Also you want a matrix for each row containing Taxonomy and IM.type in the 
output. When I run what I think you are asking, I only get a two element list, 
each a vector of values. Maybe this is what you want, and it could be coerced 
into matrix format:

D<- data.frame(Ref.No = c(1622, 1623, 1624, 1625, 1626, 1627, 1628, 1629),  
Region = rep(c('South America'), times = 8),  IM.type = c('PGA', 'PGA', 'PGA', 
'PGA', 'Sa', 'Sa', 'Sa', 'Sa'),  Damage.state = c('DS1', 'DS2', 'DS3', 
'DS4','DS1', 'DS2', 'DS3', 'DS4'),  Taxonomy = 
c('ER+ETR_H1','ER+ETR_H1','ER+ETR_H1','ER+ETR_H1','ER+ETR_H2','ER+ETR_H2','ER+ETR_H2','ER+ETR_H2'),
 Prob.of.exceedance_1 = c(0,0,0,0,0,0,0,0),
 Prob.of.exceedance_2 = c(0,0,0,0,0,0,0,0),
 Prob.of.exceedance_3 =
  c(0.26,0.001,0.00019,0.00573,0.04,0.00017,0.000215,0.000472),
 Prob.of.exceedance_4 =
  c(0.72,0.03,0.008,0.61,0.475,0.0007,0.00435,0.000405),
 stringsAsFactors=FALSE)

# names of the variables used in the calculations
calc_vars<-paste("Prob.of.exceedance",1:4,sep="_")
# get the rows for the four damage states DS1_rows <-D$Damage.state == "DS1"
DS2_rows <-D$Damage.state == "DS2"
DS3_rows <-D$Damage.state == "DS3"
DS4_rows <-D$Damage.state == "DS4"
# create an empty list
VC<-list()
# set an index variable for VC
VCindex<-1
# step through all possible values of IM.type and Taxonomy for(IM in 
unique(D$IM.type)) {  for(Tax in unique(D$Taxonomy)) {
  # get a logical vector of the rows to be used in this calculation
  calc_rows <- D$IM.type == IM & D$Taxonomy == Tax
  cat(IM,Tax,calc_rows,"\n")
  # check that there are any such rows in the data frame
  if(sum(calc_rows)) {
   # if so, fill in the four values for these rows
   VC[[VCindex]] <- 0.0 * (1- D[calc_rows & DS1_rows,calc_vars]) +
0.02* (D[calc_rows & DS1_rows,calc_vars] -
   D[calc_rows & DS2_rows,calc_vars]) +
0.10* (D[calc_rows & DS2_rows,calc_vars] -
   D[calc_rows & DS3_rows,calc_vars]) +
0.43 * (D[calc_rows & DS3_rows,calc_vars] -
   D[calc_rows & DS4_rows,calc_vars]) +
1.0*   D[calc_rows & DS4_rows,calc_vars]
   # increment the index
   VCindex<-VCindex+1
  }
 }
}

I think we'll get there.

Jim


On Sat, Dec 21, 2019 at 12:45 AM Ioannou, Ioanna  
wrote:
>
> Hello Jim,
>
> I made some changes to the code essentially I substitute each 4 lines DS1-4 
> with one. I estimate VC which in an ideal world should be a matrix with 4 
> columns one for every exceedance_probability_1-4 and 2 rowsfor each unique 
> combination of taxonomy and IM.Type. Coukd you please check the code I sent 
> last and based on that give your solution?
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] How to create a new data.frame based on calculation of subsets of an existing data.frame

2019-12-20 Thread Ioannou, Ioanna
Hello Jim,

I made some changes to the code essentially I substitute each 4 lines DS1-4 
with one. I estimate VC which in an ideal world should be a matrix with 4 
columns one for every exceedance_probability_1-4 and 2 rowsfor each unique 
combination of taxonomy and IM.Type. Coukd you please check the code I sent 
last and based on that give your solution?

Many thanks.

Get Outlook for Android<https://aka.ms/ghei36>


From: Jim Lemon 
Sent: Friday, December 20, 2019 11:40:28 AM
To: Ioannou, Ioanna 
Cc: r-help mailing list 
Subject: Re: [R] How to create a new data.frame based on calculation of subsets 
of an existing data.frame

Hi Ioanna,
For simplicity assume that the new data frame will be named E:

E<-D[,c("Taxonomy","IM.type",paste("VC,1:4,sep="_"))]

While I haven't tested this, I'm pretty sure I have it correct. Just
extract the columns you want from D and assign that to E.

Jim

On Fri, Dec 20, 2019 at 9:02 PM Ioannou, Ioanna
 wrote:
>
> Hello Jim,
>
> Thank you every so  much it ws very helful. In fact what I want to calculate 
> is the following. My very last question is if I want to save the outcome VC, 
> IM.type and Taxonomy in a new data.frame how can I do it?
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] How to create a new data.frame based on calculation of subsets of an existing data.frame

2019-12-20 Thread Ioannou, Ioanna
Hello Jim, 

Thank you every so  much it ws very helful. In fact what I want to calculate is 
the following. My very last question is if I want to save the outcome VC, 
IM.type and Taxonomy in a new data.frame how can I do it?

# names of the variables used in the calculations
calc_vars<-paste("Prob.of.exceedance",1:4,sep="_")
# get the rows for the four damage states 
DS1_rows <-D$Damage.state == "DS1"
DS2_rows <-D$Damage.state == "DS2"
DS3_rows <-D$Damage.state == "DS3"
DS4_rows <-D$Damage.state == "DS4"
# step through all possible values of IM.type and Taxonomy 
for(IM in unique(D$IM.type)) {  for(Tax in unique(D$Taxonomy)) {
# get a logical vector of the rows to be used in this calculation
calc_rows <- D$IM.type == IM & D$Taxonomy == Tax
cat(IM,Tax,calc_rows,"\n")
# check that there are any such rows in the data frame
if(sum(calc_rows)) {
  # if so, fill in the four values for these rows
  VC <- 0.0 * (1- D[calc_rows & DS1_rows,calc_vars]) +
0.02* (D[calc_rows & DS1_rows,calc_vars] -
   D[calc_rows & DS2_rows,calc_vars]) +
0.10* (D[calc_rows & DS2_rows,calc_vars] -
   D[calc_rows & DS3_rows,calc_vars]) +
0.43 * (D[calc_rows & DS3_rows,calc_vars] -
   D[calc_rows & DS4_rows,calc_vars]) +
1.0*   D[calc_rows & DS4_rows,calc_vars]

}
}
}

-----Original Message-
From: Jim Lemon [mailto:drjimle...@gmail.com] 
Sent: Thursday, December 19, 2019 2:05 AM
To: Ioannou, Ioanna ; r-help mailing list 

Subject: Re: [R] How to create a new data.frame based on calculation of subsets 
of an existing data.frame

Hi Ioanna,
I looked at the problem this morning and tried to work out what you wanted. 
With a problem like this, it is often easy when you have someone point to the 
data and say "I want this added to that and this multiplied by that". I have 
probably made the wrong guesses, but I hope that you can correct my guesses and 
I can get the calculations correct for you. For example, I have assumed that 
you want the sum of the IM_* values for each set of damage states as the values 
for VC_1,
VC_2 etc.

D<-data.frame(Ref.No = c(1622, 1623, 1624, 1625, 1626, 1627, 1628, 1629),  
Region = rep(c('South America'), times = 8),  IM.type = c('PGA', 'PGA', 'PGA', 
'PGA', 'Sa', 'Sa', 'Sa', 'Sa'),  Damage.state = c('DS1', 'DS2', 'DS3', 
'DS4','DS1', 'DS2', 'DS3', 'DS4'),  Taxonomy = 
c('ER+ETR_H1','ER+ETR_H1','ER+ETR_H1','ER+ETR_H1','ER+ETR_H2',
 'ER+ETR_H2','ER+ETR_H2','ER+ETR_H2'),
 IM_1 = c(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
 IM_2 = c(0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08),
 IM_3 = c(0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16),
 IM_4 = c(0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24),
 Prob.of.exceedance_1 = c(0,0,0,0,0,0,0,0),
 Prob.of.exceedance_2 = c(0,0,0,0,0,0,0,0),
 Prob.of.exceedance_3 =
 c(0.26,0.001,0.00019,0.00573,0.04,0.00017,0.000215,0.000472),
 Prob.of.exceedance_4 =
 c(0.72,0.03,0.008,0.61,0.475,0.0007,0.00435,0.000405),
 stringsAsFactors=FALSE)
# assume the above has been read in
# add the four columns to the data frame filled with NAs 
D$VC_1<-D$VC_2<-D$VC_3<-D$VC_4<-NA
# names of the variables used in the calculations
calc_vars<-paste("Prob.of.exceedance",1:4,sep="_")
# get the rows for the four damage states DS1_rows<-D$Damage.state == "DS1"
DS2_rows<-D$Damage.state == "DS2"
DS3_rows<-D$Damage.state == "DS3"
DS4_rows<-D$Damage.state == "DS4"
# step through all possible values of IM.type and Taxonomy for(IM in 
unique(D$IM.type)) {  for(Tax in unique(D$Taxonomy)) {
  # get a logical vector of the rows to be used in this calculation
  calc_rows<-D$IM.type == IM & D$Taxonomy == Tax
  cat(IM,Tax,calc_rows,"\n")
  # check that there are any such rows in the data frame
  if(sum(calc_rows)) {
   # if so, fill in the four values for these rows
   D$VC_1[calc_rows]<-sum(0.01 * (D[calc_rows & DS1_rows,calc_vars] -
D[calc_rows & DS2_rows,calc_vars]))
   D$VC_2[calc_rows]<-sum(0.02 * (D[calc_rows & DS2_rows,calc_vars] -
D[calc_rows & DS3_rows,calc_vars]))
   D$VC_3[calc_rows]<-sum(0.43 * (D[calc_rows & DS3_rows,calc_vars] -
D[calc_rows & DS4_rows,calc_vars]))
   D$VC_4[calc_rows]<-sum(D[calc_rows & DS4_rows,calc_vars])
  }
 }
}

Jim
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] How to save output of multiple unique loops in R.

2019-12-20 Thread Ioanna Ioannou
Hello everyone,

Could you please let me know how to create a new data.frame with the output of 
the 2 unique loops. Essentially i want a data.frame with the IM, Taxonomy and 
VC . MInd you VC is a vector with 33 elements.

Any ideas?

best,
ioanna

D<- data.frame(Ref.No = c(1622, 1623, 1624, 1625, 1626, 1627, 1628, 1629),  
Region = rep(c('South America'), times = 8),
   IM.type = c('PGA', 'PGA', 'PGA', 'PGA', 'Sa', 'Sa', 'Sa', 'Sa'),
   Damage.state = c('DS1', 'DS2', 'DS3', 'DS4','DS1', 'DS2', 'DS3', 
'DS4'),
   Taxonomy = 
c('ER+ETR_H1','ER+ETR_H1','ER+ETR_H1','ER+ETR_H1','ER+ETR_H2','ER+ETR_H2','ER+ETR_H2','ER+ETR_H2'),
   Prob.of.exceedance_1 = c(0,0,0,0,0,0,0,0),
   Prob.of.exceedance_2 = c(0,0,0,0,0,0,0,0),
  Prob.of.exceedance_3 
=c(0.26,0.001,0.00019,0.00573,0.04,0.00017,0.000215,0.000472),
  Prob.of.exceedance_4 =
c(0.72,0.03,0.008,0.61,0.475,0.0007,0.00435,0.000405),
  stringsAsFactors=FALSE)



# names of the variables used in the calculations
calc_vars<-paste("Prob.of.exceedance",1:4,sep="_")
# get the rows for the four damage states
DS1_rows <-D$Damage.state == "DS1"
DS2_rows <-D$Damage.state == "DS2"
DS3_rows <-D$Damage.state == "DS3"
DS4_rows <-D$Damage.state == "DS4"
# step through all possible values of IM.type and Taxonomy
for(IM in unique(D$IM.type)) {  for(Tax in unique(D$Taxonomy)) {
# get a logical vector of the rows to be used in this calculation
calc_rows <- D$IM.type == IM & D$Taxonomy == Tax
cat(IM,Tax,calc_rows,"\n")
# check that there are any such rows in the data frame
if(sum(calc_rows)) {
  # if so, fill in the four values for these rows
  VC <- 0.0 * (1- D[calc_rows & DS1_rows,calc_vars]) +
0.02* (D[calc_rows & DS1_rows,calc_vars] -
   D[calc_rows & DS2_rows,calc_vars]) +
0.10* (D[calc_rows & DS2_rows,calc_vars] -
   D[calc_rows & DS3_rows,calc_vars]) +
0.43 * (D[calc_rows & DS3_rows,calc_vars] -
   D[calc_rows & DS4_rows,calc_vars]) +
1.0*   D[calc_rows & DS4_rows,calc_vars]

}
}
}



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] How to create a new data.frame based on calculation of subsets of an existing data.frame

2019-12-17 Thread Ioannou, Ioanna
Hello everyone,

I have the following problem: I have a data.frame with multiple fields.

If I had to do my calculations for a given combination of IM.type and Taxonomy 
is the following:
D <- read.csv('Test_v2.csv')
names(D)

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])

So the question is how can I do that in an automated way for all possible 
combinations and store the results in new data.frame  which would look like 
this:

Ref.No. Region  IM.type TaxonomyIM_1IM_2IM_3IM_4VC_1
VC_2VC_3VC_4
1622South America   PGA ER+ETR_H1   1.00E-060.080.16
0.24  3.49e-294   3.449819e-05  0.002748889 0.01122911

Best, ,
ioanna

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] FW: How to create a new data.frame based on calculation of subsets of an existing data.frame

2019-12-17 Thread ioanna ioannou
Hello everyone, 
 
I have the following problem: I have a data.frame with multiple fields. 

If I had to do my calculations for a given combination of IM.type and
Taxonomy is the following:
D <- read.csv('Test_v2.csv')
names(D)

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])

So the question is how can I do that in an automated way for all possible
combinations and store the results in new data.frame  which would look like
this:

Ref.No. Region  IM.type TaxonomyIM_1IM_2IM_3IM_4VC_1
VC_2VC_3VC_4
1622South America   PGA ER+ETR_H1   1.00E-060.080.16
0.24  3.49e-294   3.449819e-05  0.002748889 0.01122911


Best, ,
ioanna
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] How to create a new data.frame based on calculation of subsets of an existing data.frame

2019-12-17 Thread Ioanna Ioannou
Just i case you cant see the data:

Test.v2 <- data.frame(Ref.No = c(1622, 1623, 1624, 1625, 1626, 1627, 1628, 
1629),
  IM.type = c('PGA', 'PGA', 'PGA', 'PGA', 'Sa', 'Sa', 'Sa', 
'Sa'),
  Damage.state = c('DS1', 'DS2', 'DS3', 'DS4','DS1', 'DS2', 
'DS3', 'DS4'),
  Taxonomy = 
c('ER+ETR_H1','ER+ETR_H1','ER+ETR_H1','ER+ETR_H1','ER+ETR_H2','ER+ETR_H2','ER+ETR_H2','ER+ETR_H2'),
  IM_1 = c(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
  IM_2 = c(0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08),
  IM_3 = c(0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16),
  IM_1 = c(0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24),
  Prob.of.exceedance_1 = c(0,0,0,0,0,0,0,0),
  Prob.of.exceedance_2 = c(0,0,0,0,0,0,0,0),
  Prob.of.exceedance_3 = 
c(0.26,0.001,0.00019,0.00573,0.04,0.00017,0.000215,0.000472),
  Prob.of.exceedance_4 = 
c(0.72,0.03,0.008,0.61,0.475,0.0007,0.00435,0.000405)
  )

From: R-help  on behalf of Ioanna Ioannou 

Sent: 17 December 2019 19:43
To: r-help@r-project.org 
Subject: [R] FW: How to create a new data.frame based on calculation of subsets 
of an existing data.frame


Hello everyone,


I have the following problem: I have a data.frame with multiple fields.

If I had to do my calculations for a given combination of IM.type and Taxonomy 
is the following:

D <- read.csv('Test_v2.csv')

names(D)

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])

So the question is how can I do that in an automated way for all possible 
combinations and store the results in new data.frame  which would look like 
this:

Ref.No. Region  IM.type TaxonomyIM_1   IM_2   IM_3   IM_4   VC_1   VC_2 
  VC_3   VC_4
1622   South America   PGA ER+ETR_H1   1.00E-06   0.08   0.16   
0.24 3.49e-294   3.449819e-05  0.002748889 0.01122911

Thanks in advance,

Best, ,

ioanna

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] FW: How to create a new data.frame based on calculation of subsets of an existing data.frame

2019-12-17 Thread Ioanna Ioannou


Hello everyone,


I have the following problem: I have a data.frame with multiple fields.

If I had to do my calculations for a given combination of IM.type and Taxonomy 
is the following:

D <- read.csv('Test_v2.csv')

names(D)

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])

So the question is how can I do that in an automated way for all possible 
combinations and store the results in new data.frame  which would look like 
this:

Ref.No. Region  IM.type TaxonomyIM_1   IM_2   IM_3   IM_4   VC_1   VC_2 
  VC_3   VC_4
1622   South America   PGA ER+ETR_H1   1.00E-06   0.08   0.16   
0.24 3.49e-294   3.449819e-05  0.002748889 0.01122911

Thanks in advance,

Best, ,

ioanna

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] How to create a new data.frame based on calculation of subsets of an existing data.frame

2019-12-17 Thread Ioanna Ioannou
Hello everyone,


I have the following problem: I have a data.frame with multiple fields.

If I had to do my calculations for a given combination of IM.type and Taxonomy 
is the following:

D <- read.csv('Test_v2.csv')

names(D)

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])

So the question is how can I do that in an automated way for all possible 
combinations and store the results in new data.frame  which would look like 
this:

Ref.No. Region  IM.type TaxonomyIM_1   IM_2   IM_3   IM_4   VC_1   VC_2 
  VC_3   VC_4
1622   South America   PGA ER+ETR_H1   1.00E-06   0.08   0.16   
0.24 3.49e-294   3.449819e-05  0.002748889 0.01122911

Thanks in advance,

Best, ,

ioanna

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Manipulation of data.frame into an array

2018-05-24 Thread Ioanna Ioannou
Hello everyone,


Thank you for this. Nonetheless it is not exactly want i need.


I need mydata[[1]] to provide the values for all 3 variables (Y, X1 and X2) of 
the first imputation only. As it stands it returns the whole database.

Any ideas?


Best,

ioanna




From: Bert Gunter 
Sent: 24 May 2018 16:04
To: Ioanna Ioannou
Cc: r-help@r-project.org
Subject: Re: [R] Manipulation of data.frame into an array

This is one of those instances where a less superficial knowledge of R's 
technical details comes in really handy.

What you need to do is convert the data frame to a single (numeric) vector for, 
e.g. a matrix() call. This can be easily done by noting that a data frame is 
also a list and using do.call():

## imp is the data frame:

do.call(c,imp)

 X11  X12  X13  X14  X15  X16  X17  X18  X19 X110 X111 X112 X113 X114
   12121212121212
X115 X116  X21  X22  X23  X24  X25  X26  X27  X28  X29 X210 X211 X212
   12010111010101
X213 X214 X215 X216   Y1   Y2   Y3   Y4   Y5   Y6   Y7   Y8   Y9  Y10
   11011234567812
 Y11  Y12  Y13  Y14  Y15  Y16
   345678

So, e.g. for a 3 column matrix:

> matrix(do.call(c,imp), ncol=3)
  [,1] [,2] [,3]
 [1,]101
 [2,]212
 [3,]103
 [4,]214
 [5,]115
 [6,]216
 [7,]107
 [8,]218
 [9,]101
[10,]212
[11,]103
[12,]214
[13,]115
[14,]216
[15,]107
[16,]218

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and 
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Thu, May 24, 2018 at 7:46 AM, Ioanna Ioannou 
mailto:ii54...@msn.com>> wrote:
Hello everyone,


 I want to transform a data.frame into an array (lets call it mydata), where: 
mydata[[1]] is the first imputed dataset...and for each mydata[[d]], the first 
p columns are covariates X, and the last one is the outcome Y.


Lets assume a simple data.frame:


Imputed = data.frame( X1 = c(1,2,1,2,1,2,1,2, 1,2,1,2,1,2,1,2),

  X2 = c(0,1,0,1,1,1,0,1, 
0,1,0,1,1,1,0,1),

   Y   = 
c(1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8))

The first 8 have been obtained by the first imputation and the later 8 by the 
2nd.


Can you help me please?


Best,

ioanna

[[alternative HTML version deleted]]

__
R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To 
UNSUBSCRIBE and more, see
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.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Manipulation of data.frame into an array

2018-05-24 Thread Ioanna Ioannou
Hello everyone,


 I want to transform a data.frame into an array (lets call it mydata), where: 
mydata[[1]] is the first imputed dataset...and for each mydata[[d]], the first 
p columns are covariates X, and the last one is the outcome Y.


Lets assume a simple data.frame:


Imputed = data.frame( X1 = c(1,2,1,2,1,2,1,2, 1,2,1,2,1,2,1,2),

  X2 = c(0,1,0,1,1,1,0,1, 
0,1,0,1,1,1,0,1),

   Y   = 
c(1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8))

The first 8 have been obtained by the first imputation and the later 8 by the 
2nd.


Can you help me please?


Best,

ioanna

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Change values of a column based on the values of a third

2015-10-05 Thread IOANNA IOANNOU
Hello all, 

 

I have a rather easy question. I want to add a column to the database which
will change the values of vector a based on the values to vector b. Any
ideas how?

 

For example:

 

Dat <- data.frame(a= c('A','A','C','B','D','D','B'),

  b= c('N','N','Y','N','Y','N','N') )

 

I want to add a column c which will change 'C' to 'D' if column b is 'Y'.

 


> Dat

  a b c

1 A N A

2 A N A

3 C Y D

4 B N B

5 C Y D

6 C N C

7 B N B




Any ideas?

 

Best, 

ioanna

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] FW: Completing Unordered Categorical missing variables using package mi

2015-06-18 Thread IOANNA IOANNOU
 

Hello all, 

 

A perhaps simple question. I am trying to complete unordered categorical
missing data using mi package. There are two variables with missing data:
Mat and Use. The problem is that the Use has several categories and somehow
this means I can't plot the results as I get this error. Any idea how to fix
the problem?

Any help much appreciated, 

Best, 

Ioanna

 

new<-read(Sample.csv)

new$Use<-factor(new$Use)

MissingData <- missing_data.frame(new)

MissingData <- change(MissingData, y = "DS", what = "type", to =
"ordered-categorical")

 

# STEP 3: look deeper

summary(MissingData)

summary(MissingData@patterns)

show(MissingData)

hist(MissingData)

 

 

# STEP 4: impute

## Not run: 

IMPsample <- mi(MissingData)

 

 

#STEP5: diagnostics

Plot(IMPsample)

 

Error in `rownames<-`(`*tmp*`, value = c("Oc11", "Oc12", "Oc13", "Oc14",  : 

  length of 'dimnames' [1] not equal to array extent

 

Data

new

  DS  Use Material SurfaceIM

31237  3 Oc22 Wood   95.710401 3.148

48947  1 Oc19 Wood  124.427200 1.762

7038   5 Oc11 Wood  142.113800 1.890

8150   3 Oc32Steel   70.709451 2.530

43471  1 Oc19   NA3.609650 1.597

24815  5 Oc11 Wood  121.541500 3.638

8683   2 Oc11 Wood   80.341550 2.242

47303  1 Oc39   NA   19.018000 1.410

27467  5 Oc11 Wood   86.799050 3.782

35026  2 Oc11 Wood  113.185700 2.565

50635  5 Oc19   NA   28.169550 3.887

9459   2 Oc11 Wood   40.825350 1.779

14042  2 Oc13Steel   36.233100 4.293

17393  3 Oc11 Wood   56.069700 2.833

21157  5 Oc11 Wood   89.254700 4.958

42345  2 Oc19   NA2.973600 0.468

4372   5 Oc11 Wood7.872750 3.950

16654  5 Oc11 Wood   75.315600 6.395

47335  1 Oc19   NA   14.564400 1.781

49609  5 Oc19   NA   17.249000 3.545

4973   5 Oc19 Wood   28.511699 3.243

44784  2 Oc19   NA4.473000 2.328

29581  5 Oc11 Wood   96.884250 4.378

31949  3 Oc11 Wood  126.996500 3.225

7352   5 Oc11 Wood   71.905200 3.430

43139  1 Oc19   NA  133.573551 1.849

43350  2 Oc19   NA3.739350 1.205

11592  2 Oc11 Wood   72.146800 2.906

33767  3 Oc11 Wood   91.578001 2.905

51748  5 Oc39   NA9.108800 3.138

21160  5 Oc12 Wood  100.677100 4.268

34390  2 Oc12 Wood  120.401199 1.603

23255  5 Oc12 Wood  122.333801 5.557

38414  2 Oc21Steel   69.686100 3.021

48810  3 Oc29 Wood   79.609950 3.670

44611  2 Oc19   NA   15.328000 1.480

17905  3 Oc11 Wood   61.188500 1.857

35509  2 Oc11 Wood  160.180349 2.511

10252  2 Oc11 Wood   94.414799 1.446

47152  2 Oc19 Wood   12.160450 2.285

43221  2 Oc11 Wood   70.796299 1.361

32569  3 Oc11 Wood   97.269300 2.842

5671   5 Oc11 Wood   84.672250 3.050

1157   3 Oc11 Wood   79.297800 2.612

3441   2 Oc11 Wood  112.435650 2.105

36678  5 Oc21 Wood   27.223500 4.017

52241  5 Oc19 Wood3.946150 3.373

4688   5 Oc11 Wood   68.009700 3.766

42933  2 Oc19 Wood3.946801 2.039

31048  5 Oc11 Wood   25.172301 3.633

28660  1 Oc11 Wood  133.387099 1.285

22726  5 Oc12 Wood  216.952900 7.550

22397  5 Oc11 Wood  115.320750 5.825

41008  3 Oc11 Wood   97.253199 1.960

49054  3 Oc21   NA8.542800 1.329

5594   5 Oc41   RC  264.505000 3.185

45379  3 Oc41 Wood   39.357100 2.909

17498  3 Oc11 Wood   45.544750 1.459

1176   5 Oc11 Wood   87.020400 2.750

33055  1 Oc11 Wood   55.777250 1.437

37071  5 Oc32 Wood  201.629599 3.287

53813  5 Oc19 Wood   56.919600 4.322

11037  2 Oc11 Wood  107.886600 1.479

14453  2 Oc11 Wood  106.369949 2.508

3767   1 Oc11 Wood   71.325500 2.012

52303  5 Oc29   NA8.916150 6.092

19706  5 Oc19 Wood   25.936699 6.417

37658  5 Oc14 Wood   65.761651 4.317

26195  1 Oc12 Wood   82.510849 0.835

35808  3 Oc13 Wood   54.798851 2.337

6035   5 Oc12 Wood  286.075700 3.905

33383  3 Oc11 Wood   96.809150 2.560

43497  1 Oc19   NA   13.039000 1.103

41777  5   NA   NA   47.153349 2.658

12024  2 Oc11 Wood   19.851000 2.567

39538  1 Oc19   NA   31.996200 2.108

15553  3 Oc19 Wood  197.062201 2.559

31522  3 Oc11 Wood  129.499700 2.906

11916  2 Oc11 Wood   58.358951 2.939

9688   2 Oc11 Wood  106.568201 1.822

1690   3 Oc11 Wood  202.613700 2.290

9773 Oc11 Wood  179.321800 1.987

12410  2 Oc14Steel  108.682100 2.821

52428  5 Oc19   NA   36.041699 6.042

14109  2 Oc21Steel  130.929300 4.178

52769  5 Oc31 Wood   18.525650 2.187

11324  1 Oc11 Wood   94.108351 1.456

12394  2 Oc21   RC 1836.975800 2.415

35991  3 Oc11 Wood  114.716550 2.664

4006   5 Oc39Steel  309.854000 4.041

43404  2 Oc19   RC   27.745400 1.772

12680  1 Oc21   RC  327.789699 2.669

43607  1 Oc29   NA5.812499 2.406

335

[R] Completing Unordered Categorical missing variables using package mi

2015-06-18 Thread IOANNA IOANNOU
Hello all, 

 

A perhaps simple question. I am trying to complete unordered categorical
missing data using mi package. There are two variables with missing data:
Mat and Use. The problem is that the Use has several categories and somehow
this means I can't plot the results as I get this error. Any idea how to fix
the problem?

Any help much appreciated, 

Best, 

Ioanna

 

new<-read(Sample.csv)

new$Use<-factor(new$Use)

MissingData <- missing_data.frame(new)

MissingData <- change(MissingData, y = "DS", what = "type", to =
"ordered-categorical")

 

# STEP 3: look deeper

summary(MissingData)

summary(MissingData@patterns)

show(MissingData)

hist(MissingData)

 

 

# STEP 4: impute

## Not run: 

IMPsample <- mi(MissingData)

 

 

#STEP5: diagnostics

Plot(IMPsample)

 

Error in `rownames<-`(`*tmp*`, value = c("Oc11", "Oc12", "Oc13", "Oc14",  : 

  length of 'dimnames' [1] not equal to array extent

 

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] gaussian Kernel smoothing using Nadaraya-Watson estimator and confidence bands

2015-03-05 Thread IOANNA IOANNOU
Hello, 

I have a database and I would like to fit a Nadaraya-Watson Gaussian kernel
estimator and produce the confidence bands around the  mean estimate. Any
ideas how to do this with R? I cannot find a way to produce the confidence
bands. I will use a fixed bandwidth. 


Lets use this database for illustration purposes:

d <- data.frame(x = runif(N))
d$y <- d$x^2 - d$x + 1 + (1+d$x)*rnorm(N, sd = 0.1)


Any help much appreciated. 


Best, 
Ioanna

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] FW: FW: confidence intervals values in locpol

2015-03-04 Thread IOANNA IOANNOU

 Hello all,
 
 A straightforward question. How can I get a the values of the 90% 
 confidence intervals of a locpol in R? I can see how you can plot the 
 mean as well as the confidence intervals. I would like the matrix of 
 the values corresponding to the 95% and 5% exceedance probability.
 
 Any ideas?
 
 For example
 
 N <- 250
 xeval <- 0:100/100
 ##  ex1
 d <- data.frame(x = runif(N))
 d$y <- d$x^2 - d$x + 1 + rnorm(N, sd = 0.1)
 r <- locpol(y~x,d)
 plot(r)
 
 Best,
 Ioanna
 

-
E-Mail: (Ted Harding) 
Date: 03-Mar-2015  Time: 23:28:20
This message was sent by XFMail

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Legend having lines with different types

2014-05-28 Thread IOANNA
 

Hello all, 

 

I want to plot the legend for the following two lines:

I have two lines:

 

X1<-c(0,1,2,3,4)

Y1<-c(0,1,2,3,4)

 

Y2<-c(5,6,7,8,9)

 

Y3<-(32,33,34,35,36)

 

plot(X1,Y3,pch=20)

lines(X1,Y1,lty=1,type='o')

lines(X1,Y2,lty=1,type='b')

lines(X1,Y3,lty=2)

 

Any ideas how?

 

Best 

IOanna


[[alternative HTML version deleted]]

__
R-help@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.


[R] LInes with types

2014-05-27 Thread ioanna ioannou
Hello all, 

 

I want to plot the legend for the following two lines:

I have two lines:

 

X1<-c(0,1,2,3,4)

Y1<-c(0,1,2,3,4)

 

Y2<-c(5,6,7,8,9)

 

Y3<-(32,33,34,35,36)

 

plot(X1,Y3,pch=20)

lines(X1,Y1,lty=1,type='o')

lines(X1,Y2,lty=1,type='b')

lines(X1,Y3,lty=2)

 

Any ideas how?

 

Best 

IOanna


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] grf in geoR

2014-03-31 Thread ioanna ioannou
 

Hello all, 

 

A simple question. When I use grf from the package 'geoR' , I adopt the
exponential model. For this model is the parameter phi in m or km?

 

Best 

ioanna


[[alternative HTML version deleted]]

__
R-help@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.


[R] grf in geoR

2014-03-31 Thread ioanna ioannou
Hello all, 

 

A simple question. When I use grf from the package 'geoR' , I adopt the
exponential model. For this model is the parameter range in m or km?

 

Best 

ioanna


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Data manipulation in a data.frame

2014-02-21 Thread ioanna ioannou
Thank you very much. One further question. 

Assuming that for some points there is no classification for example:

A<-data.frame(A=c(10,100,1000,30,50,60,300,3),

  B=c(0,1,1,1,0,0,0,0),

  C=c(0,0,0,0,1,1,0,0),

  D=c(1,0,0,0,0,0,1,0))

Is there an easy way to introduce an extra none option in the variable?

A<-data.frame(A=c(10,100,1000,30,50,60,300,3),

  B=c(0,1,1,1,0,0,0,0),

  C=c(0,0,0,0,1,1,0,0),

  D=c(1,0,0,0,0,0,1,0),

   Variable=c(D,B,B,B,C,C,D,none))

Thanks in advance, 
IOanna

-Original Message-
From: arun [mailto:smartpink...@yahoo.com] 
Sent: 21 February 2014 00:19
To: r-help@r-project.org
Cc: ioanna ioannou
Subject: Re: [R] Data manipulation in a data.frame

Also,
rownames(which(t(!!A[,-1]),arr.ind=TRUE))
A.K.




On Thursday, February 20, 2014 6:48 PM, arun  wrote:
Hi,
May be this helps:

A$Variable <- rep(colnames(A[,-1]),nrow(A))[t(!!A[,-1])]
A.K.



On Thursday, February 20, 2014 5:55 PM, ioanna ioannou 
wrote:
Hello,





Assuming that I have a data frame 

A<-data.frame(A=c(10,100,1000,30,50,60,300),

              B=c(0,1,1,1,0,0,0),                        

              C=c(0,0,0,0,1,1,0),

              D=c(1,0,0,0,0,0,1))



What I would like is to introduce a new column Variable such that:



A<-data.frame(A=c(10,100,1000,30,50,60,300),

              B=c(0,1,1,1,0,0,0),                        

              C=c(0,0,0,0,1,1,0),

              D=c(1,0,0,0,0,0,1),

       Variable=c(D,B,B,B,C,C,D)) 



How can I do it?



Best 

IOanna


    [[alternative HTML version deleted]]

__
R-help@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.

__
R-help@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.


[R] Data manipulation in a data.frame

2014-02-20 Thread ioanna ioannou
Hello,

 

 

Assuming that I have a data frame 

A<-data.frame(A=c(10,100,1000,30,50,60,300),

  B=c(0,1,1,1,0,0,0),

  C=c(0,0,0,0,1,1,0),

  D=c(1,0,0,0,0,0,1))

 

What I would like is to introduce a new column Variable such that:

 

A<-data.frame(A=c(10,100,1000,30,50,60,300),

  B=c(0,1,1,1,0,0,0),

  C=c(0,0,0,0,1,1,0),

  D=c(1,0,0,0,0,0,1),

   Variable=c(D,B,B,B,C,C,D)) 

 

How can I do it?

 

Best 

IOanna


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Aggregating spatial data

2013-11-26 Thread IOANNA
Fantastic. Thanks very much! Is there an easy  way to plot the points and
the 4 areas?

Best, 
Ioanna

-Original Message-
From: David Carlson [mailto:dcarl...@tamu.edu] 
Sent: 25 November 2013 15:21
To: 'IOANNA'; r-help@r-project.org
Subject: RE: [R] Aggregating spatial data

Something like this?

> s <- expand.grid(x=seq(1,100,by=1),y=seq(1,100,by=1))
> w <-
data.frame(x=s$x,y=s$y,z1=rep(c(1,2,3,4),times=length(s$x/4)),
+   z2=seq(1,length(s$x),by=1))
> w$EW <- cut(w$x, breaks=c(.5, 50.5, 100.5), labels=c("West",
"East"))
> w$NS <- cut(w$y, breaks=c(.5, 50.5, 100.5), labels=c("South",
"North"))
> aggregate(z1~EW+NS, w, table)
EWNS z1.1 z1.2 z1.3 z1.4
1 West South 2600 2600 2400 2400
2 East South 2400 2400 2600 2600
3 West North 2600 2600 2400 2400
4 East North 2400 2400 2600 2600
> table(w$z1)

1 2 3 4 
1 1 1 1 
> aggregate(z2~EW+NS, w, mean)
EWNS z2
1 West South 2475.5
2 East South 2525.5
3 West North 7475.5
4 East North 7525.5

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of IOANNA
Sent: Monday, November 25, 2013 8:46 AM
To: r-help@r-project.org
Subject: [R] Aggregating spatial data
Importance: High

Hello all, 

 

I have a data frame in the form:

 

s<-expand.grid(x=seq(1,100,by=1),y=seq(1,100,by=1))

w<-data.frame(x=s$x,y=s$y,z1=rep(c(1,2,3,4),times=length(s$x/4))
,z2=seq(1,le
ngth(s$x),by=1))

 

The w$x and w$y represent the location of points and z1 and z2 attributes
corresponding to these points. 

 

 

My question is how to divide this area in 4 sub-areas of equal points each
and produce the counts of z1= '1', '2' , '3' in each quarter as well as mean
values of z2 for each quarter. 

 

Best, 

Ioanna


[[alternative HTML version deleted]]

__
R-help@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.

__
R-help@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.


[R] Aggregating spatial data

2013-11-25 Thread IOANNA
Hello all, 

 

I have a data frame in the form:

 

s<-expand.grid(x=seq(1,100,by=1),y=seq(1,100,by=1))

w<-data.frame(x=s$x,y=s$y,z1=rep(c(1,2,3,4),times=length(s$x/4)),z2=seq(1,le
ngth(s$x),by=1))

 

The w$x and w$y represent the location of points and z1 and z2 attributes
corresponding to these points. 

 

 

My question is how to divide this area in 4 sub-areas of equal points each
and produce the counts of z1= '1', '2' , '3' in each quarter as well as mean
values of z2 for each quarter. 

 

Best, 

Ioanna


[[alternative HTML version deleted]]

__
R-help@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.


[R] Error in grf using geoR

2013-11-12 Thread IOANNA
Hello all, 

I cant find a thread with a problem similar to mine. I am trying to create a
random fields and I get the same error:

library(geoR)
N<-10
nslon<-250
nslat<-250
range<-10
sim2 <- grf(nslon*nslat, grid="reg", nx=nslon, ny=nslat,cov.pars=c(1,
range), 
  nsim=N, cov.model = "exponential",
  xlims=c(30.02,35.00),ylims=c(30.02,35.00) )

Error in FUN(X[[1L]], ...) : 
  different grid distances detected, but the grid must have equal distances
in each direction -- try gridtriple=TRUE that avoids numerical errors.

 I can't understand why as the code seems to run if I change the limits of
the grid:

sim2 <- grf(nslon*nslat, grid="reg", nx=nslon, ny=nslat,cov.pars=c(1,
range), 
  nsim=N, cov.model = "exponential",
  xlims=c(0.02,5.00),ylims=c(0.02,5.00) )

Any ideas?

Best 
Ioanna

__
R-help@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.


Re: [R] Identifying the bin where a value is included.

2013-09-18 Thread ioanna ioannou
Hello all, 

A very simple problem. 

Lets assume I  have an interval [0,1] and I split it in 6 bins having
thresholds:
pro= cbind(0, 0.3675509, 0.8618615, 0.9814291, 0.9975283, 0.9997789,
1.000,
   0, 0.3662881, 0.8609743, 0.9812032, 0.9974822, 0.9997738,
1.000)

dim(pro)<-c(7,2)

 I randomly generate a number and I want to identify which bin it belongs
to. How? What I provide below doesn't seem to be working. 
Any ideas?

for (i in 1:2){
ids<-runif(1)
  for (j in 1:length(pro[,i])-1){
if (ids < pro[j,i]) {
  ds[i]<-j
}
else {
  ds[i]<-6
    } 
  }
}

Best, 
IOanna

__
R-help@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.


[R] FW: Kernel smoothing with bandwidth which varies with x

2013-05-23 Thread IOANNA
Hello all, 

I would like to use the Nadaraya-Watson estimator assuming a Gaussian
kernel: So far I sued the 
library(sm)
library(sm)
x<-runif(5000)
y<-rnorm(5000)
plot(x,y,col='black')
h1<-h.select(x,y,method='aicc')
lines(ksmooth(x,y,bandwidth=h1))

which works fine. What if my data were clustered requiring a bandwidth that
varies with x? How can I do that?

Thanks in advance, 
Ioanna

__
R-help@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.


[R] Reshaping a table

2013-04-08 Thread IOANNA
Hello all, 

 

I have data in the form of a table:

 

X  Y1Y2

0.1   3   2

0.2   2   1

 

And I would like to transform in the form:

 

X Y

0.1   Y1

0.1   Y1

0.1   Y1

0.1   Y2

0.1   Y2

0.2  Y1

0.2  Y1

0.2  Y2

 

Any ideas how?

 

Thanks in advance, 

IOanna

 

 

 


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Data manipulation

2013-03-15 Thread IOANNA

Hello John, 


I thought I attached the file. So here we go: 
Class=c(1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,
3,3,3,3,3,3,3)
X=c(0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.1,0.1,
0.1,0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.2,0.3,0.3,0.3,0.3)
Count=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)

by1<-factor(Class)
by2<-factor(X)
W<-aggregate(x=Count,by=list(by1,by2),FUN="sum")

 

However, what I want is a table that also include lines for the Group.1 and
Group.2 values for which there are no records. In other words something like
this:

 

Thanks again. I hope its clearer now. 
Ioanna


-Original Message-
From: John Kane [mailto:jrkrid...@inbox.com] 
Sent: 15 March 2013 12:51
To: IOANNA; r-help@r-project.org
Subject: RE: [R] Data manipulation

What zero values?  And are they acutall zeros or are the NA's, that is,
missing values?

The code looks okay but without some sample data it is difficult to know
exactly what you are doing. 

The easiest way to supply data  is to use the dput() function.  Example with
your file named "testfile": 
dput(testfile)
Then copy the output and paste into your email.  For large data sets, you
can just supply a representative sample.  Usually, 
dput(head(testfile, 100)) will be sufficient.   

 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducibl
e-example

Please supply some sample data. 
 

John Kane
Kingston ON Canada


> -Original Message-
> From: ii54...@msn.com
> Sent: Fri, 15 Mar 2013 12:40:54 +
> To: r-help@r-project.org
> Subject: [R] Data manipulation
> 
> Hello all,
> 
> 
> 
> I would appreciate your thoughts on a seemingly simple problem. I have 
> a database, where each row represent a single record. I want to 
> aggregate this database so I use the aggregate command :
> 
> 
> 
> D<-read.csv("C:\\Users\\test.csv")
> 
> 
> 
> attach(D)
> 
> 
> 
> by1<-factor(Class)
> 
> by2<-factor(X)
> 
> W<-aggregate(x=Count,by=list(by1,by2),FUN="sum")
> 
> 
> 
> The results I get following the form:
> 
> 
> 
> >W
> 
>   Group.1 Group.2 x
> 
> 1   1 0.1 4
> 
> 2   2 0.1 7
> 
> 3   3 0.1 1
> 
> 4   1 0.2 3
> 
> 5   3 0.2 4
> 
> 6   3 0.3 4
> 
> 
> 
> 
> 
> However, what I really want is an aggregation which includes the zero 
> values, i.e.:
> 
> 
> 
> >W
> 
>   Group.1 Group.2 x
> 
> 1   1 0.1 4
> 
> 2   2 0.1 7
> 
> 3   3 0.1 1
> 
> 4   1 0.2 3
> 
> 2 0.2 0
> 
> 5   3 0.2 4
> 
> 10.3 0
> 
> 20.3 0
> 
> 6   3 0.3 4
> 
> 
> 
> 
> 
> How can I achieve what I want?
> 
> 
> 
> Best regards,
> 
> Ioanna
> 
> __
> R-help@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.



family!
[[elided Hotmail spam]]


__
R-help@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.


Re: [R] Data manipulation

2013-03-15 Thread IOANNA
Thanks a lot! 

-Original Message-
From: John Kane [mailto:jrkrid...@inbox.com] 
Sent: 15 March 2013 13:41
To: Blaser Nello; IOANNA; r-help@r-project.org
Subject: Re: [R] Data manipulation

Nice. That does look like it. IOANNA?

John Kane
Kingston ON Canada


> -Original Message-
> From: nbla...@ispm.unibe.ch
> Sent: Fri, 15 Mar 2013 14:27:03 +0100
> To: ii54...@msn.com, r-help@r-project.org
> Subject: Re: [R] Data manipulation
> 
> Is this what you want to do?
> 
> D2 <- expand.grid(Class=unique(D$Class), X=unique(D$X))
> D2 <- merge(D2, D, all=TRUE)
> D2$Count[is.na(D2$Count)] <- 0
> 
> W <- aggregate(D2$Count, list(D2$Class, D2$X), "sum") W
> 
> Best,
> Nello
> 
> 
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org]
> On Behalf Of IOANNA
> Sent: Freitag, 15. März 2013 13:41
> To: r-help@r-project.org
> Subject: [R] Data manipulation
> 
> Hello all,
> 
> 
> 
> I would appreciate your thoughts on a seemingly simple problem. I have 
> a database, where each row represent a single record. I want to 
> aggregate this database so I use the aggregate command :
> 
> 
> 
> D<-read.csv("C:\\Users\\test.csv")
> 
> 
> 
> attach(D)
> 
> 
> 
> by1<-factor(Class)
> 
> by2<-factor(X)
> 
> W<-aggregate(x=Count,by=list(by1,by2),FUN="sum")
> 
> 
> 
> The results I get following the form:
> 
> 
> 
> >W
> 
>   Group.1 Group.2 x
> 
> 1   1 0.1 4
> 
> 2   2 0.1 7
> 
> 3   3 0.1 1
> 
> 4   1 0.2 3
> 
> 5   3 0.2 4
> 
> 6   3 0.3 4
> 
> 
> 
> 
> 
> However, what I really want is an aggregation which includes the zero 
> values, i.e.:
> 
> 
> 
> >W
> 
>   Group.1 Group.2 x
> 
> 1   1 0.1 4
> 
> 2   2 0.1 7
> 
> 3   3 0.1 1
> 
> 4   1 0.2 3
> 
> 2 0.2 0
> 
> 5   3 0.2 4
> 
> 10.3 0
> 
> 20.3 0
> 
> 6   3 0.3 4
> 
> 
> 
> 
> 
> How can I achieve what I want?
> 
> 
> 
> Best regards,
> 
> Ioanna
> 
> __
> R-help@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.


GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at 

webmails

__
R-help@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.


[R] Data manipulation

2013-03-15 Thread IOANNA
Hello all, 

 

I would appreciate your thoughts on a seemingly simple problem. I have a
database, where each row represent a single record. I want to aggregate this
database so I use the aggregate command :

 

D<-read.csv("C:\\Users\\test.csv")

 

attach(D)

 

by1<-factor(Class)

by2<-factor(X)

W<-aggregate(x=Count,by=list(by1,by2),FUN="sum")

 

The results I get following the form:

 

>W

  Group.1 Group.2 x

1   1 0.1 4

2   2 0.1 7

3   3 0.1 1

4   1 0.2 3

5   3 0.2 4

6   3 0.3 4

 

 

However, what I really want is an aggregation which includes the zero
values, i.e.:

 

>W

  Group.1 Group.2 x

1   1 0.1 4

2   2 0.1 7

3   3 0.1 1

4   1 0.2 3

2 0.2 0

5   3 0.2 4

10.3 0

20.3 0

6   3 0.3 4

 

 

How can I achieve what I want?

 

Best regards, 

Ioanna

__
R-help@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.


[R] Issue with using geocode

2012-11-25 Thread ioanna ioannou
Hello, 

 

A very simple question but I am stuck. I have an excel file each row is an
address. However, I cannot make geocode read each line and come up with the
latitude longitude. Could you please correct my code?

 

 

library(ggmap)

 

X<-c (2 Afxentiou Ampelokipi Thessaloniki Greece, 2 Afxentiou Ampelokipi
Thessaloniki Greece, 4 Afxentiou Ampelokipi Thessaloniki Greece, 55
Agathonos Ampelokipi Thessaloniki Greece)

 

For (i in 1:4){

Y<-geocode('X')

print Y[i]

}

 

 

Best wishes, 

Ioanna

 


[[alternative HTML version deleted]]

__
R-help@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.


[R] LOCFIT

2012-07-13 Thread Ioanna Ioannou

Hello,
I am using the locfit to fit a non parametric glm model to data with a gamma 
distributed response variable. In the parametric glm regression the diagnostics 
were based on the study of the standardized deviance or pearson residuals.  How 
can I estimate the the standardized Pearson residuals for the nonparametric 
model? 
Thanks, Ioanna
[[alternative HTML version deleted]]

__
R-help@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.


[R] Error: (subscript) logical subscript too long

2012-04-02 Thread IOANNA
Hello, 

I am trying to perform a logistic regression using counts. For example:

cedegren <-
read.table("http://www.cloudstat.org/index.php?do=/attachment/download/id_95
/", header=T)
attach(cedegren)
ced.del <- cbind(sDel, sNoDel)
ced.logr <- glm(ced.del ~ cat + follows + factor(class),
family=binomial("logit"))

This works. However, if I change the family to Gaussian:

ced.logr <- glm(ced.del ~ cat + follows + factor(class), family=gaussian)

I get the error:
Error: (subscript) logical subscript too long

I would like to use the probit function. Is this possible?

Best regards, 
Ioanna

__
R-help@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.


[R] Call the Standard Error and t-test probability in linear regression

2012-03-02 Thread IOANNA
Hello, 

I run a linear regression I get the summary, e.g.:

> summary(lm.r) 
   Call: 
   lm(formula = signal ~ conc) 
   Residuals: 
  12 3  4  5  
 0.4  -1.0   1.6  -1.80.8  
   Coefficients: 
  Estimate Std.  Errort valuePr(>|t|) 
 (Intercept)  3.61.232882.92 0.0615 .   
 conc  1.94000 0.05033   38.54  3.84e-05 *** 
   --- 
   Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1  
   Residual standard error: 1.592 on 3 degrees of freedom 
   Multiple R-Squared: 0.998,  Adjusted R-squared: 0.9973  
   F-statistic:  1486 on 1 and 3 DF,  p-value: 3.842e-0

I would like to call the probability of the t-test only in order to use it
separately. For example I 'd like to get: 
Pr<-3.84e-05 

Similarly I want to call the standard error of the parameters and the
function:
SEconc<-0.05033

I don't know how to do this. Any help?

Regards, 
Ioanna

__
R-help@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.


Re: [R] plotting confidence bands from predict.nls

2012-02-05 Thread ioanna


It is not homework. My problem is this: I used nonlinear regression to fit a 
lognormal cumulative distribution to the probability of a buildings' collapse 
against a measure of seismic intensity. I am able to obtain the asymptotic 
confidence intervals. I am not , however, certain that they are accurate and I 
wonder whether a bootstrap or even a Monte carlo could improve their accuracy. 
You see I want a realistic represntation of the confidence intervals as I need 
to propagate it further in the risk assessment. Perhaps I m wrong. Could you 
please enlighten me?

Yanna
Date: Sun, 5 Feb 2012 03:42:05 -0800
From: ml-node+s789695n4358800...@n4.nabble.com
To: ii54...@msn.com
Subject: Re: plotting confidence bands from predict.nls



On 05/02/2012 08:10, ioanna wrote:

> How do you use bootstrap to estimate the confidence as well as the prediction

> intervals in nonlinear regression ?


With difficulty!


There is far too little here to go on, and this seems an odd question 

unless it is homework (why dictate a problem-strewn method of solution 

if this is a real problem?)


The real issue is how to bootstrap nonlinear regression, and you will 

find that discussed in all good books on the subject, such as Venables & 

Ripley and Davison & Hinkley.  It is not trivial and the solutions are 

not altogether satisfactory 


> --

> View this message in context: 
> http://r.789695.n4.nabble.com/plotting-confidence-bands-from-predict-nls-tp3505012p4358572.html
> Sent from the R help mailing list archive at Nabble.com.

>

> __

> [hidden email] 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.



-- 

Brian D. Ripley,  [hidden email]

Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)

1 South Parks Road, +44 1865 272866 (PA)

Oxford OX1 3TG, UKFax:  +44 1865 272595


__

[hidden email] 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.









If you reply to this email, your message will be added to the 
discussion below:

http://r.789695.n4.nabble.com/plotting-confidence-bands-from-predict-nls-tp3505012p4358800.html



To unsubscribe from plotting confidence bands from predict.nls, 
click here.

NAML
  

--
View this message in context: 
http://r.789695.n4.nabble.com/plotting-confidence-bands-from-predict-nls-tp3505012p4358822.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] plotting confidence bands from predict.nls

2012-02-05 Thread ioanna
How do you use bootstrap to estimate the confidence as well as the prediction
intervals in nonlinear regression ? 

--
View this message in context: 
http://r.789695.n4.nabble.com/plotting-confidence-bands-from-predict-nls-tp3505012p4358572.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] R: sample size package

2012-02-03 Thread IOANNA
Hello, 

 

Lets assume I have an ordinal response variable representing the
D<-c(D0,D1,D2,D3,D4) where D0 is no damage and D4 is collapse which I want
to correlate with a continuous predictor variable, wind speed at the
location of each building.

 

is  there a function in R which I can use to estimate the sample size of
buildings with a given power if I want to perform an ordinal logistic
regression? Is this sample the same if I want to use kernel smoothing? Is
this possible to estimate the sample size in D0,.,D4? Collapse is rather
rare.

 

Regards, 

Yanna 

 


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] kernel smoothing of disease rates at locations

2012-02-02 Thread ioanna
Is it possible to apply a kernel smoothing regression whose estimator or
indeed the confidence intervals cannot take negative values or values
greater than 1? 

Best regards, 
Ioanna

--
View this message in context: 
http://r.789695.n4.nabble.com/kernel-smoothing-of-disease-rates-at-locations-tp799701p4352286.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.