Hello,
in the data.frame "resultsfuzzy" I would like to replace the
characters in the second column ("5a", "5b", ...
"5e") with numbers
from 1 to 5. The data.frame has 39150 entries. I seems to work on
samples that are << nrow(resultsfuzzy) but it takes suspicously long.
Do you have any suggestions how to make the character replacing more efficient?
Code:
for (i in 1:nrow(resultsfuzzy))
{
if (resultsfuzzy[i,2] == "5a"){resultsfuzzy[i,2] <- 1} else
if (resultsfuzzy[i,2] == "5b"){resultsfuzzy[i,2] <- 2} else
if (resultsfuzzy[i,2] == "5c"){resultsfuzzy[i,2] <- 3}
else
if (resultsfuzzy[i,2] == "5d"){resultsfuzzy[i,2] <- 4}
else
resultsfuzzy[i,2] <- 5
}
Thanks,
Kim
version
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 2.1
year 2005
month 12
day 20
svn rev 36812
language R
__________________________________________
Kim Milferstedt
University of Illinois at Urbana-Champaign
Department of Civil and Environmental Engineering
4125 Newmark Civil Engineering Laboratory
205 North Mathews Avenue MC-250
Urbana, IL 61801
USA
phone: (001) 217 333-9663
fax: (001) 217 333-6968
email: milferst at uiuc.edu
http://cee.uiuc.edu/research/morgenroth
One way that might do what you want is to change the character column
to a factor, and then apply as.numeric.
resultsfuzzy$x<-as.numeric(factor(resultsfuzzy$x,levels=c("5a","5b","5c","5d","5e")))
This assumes, of course, that you know that the levels are going to be
in the set {5a,5b,5c,5d,5e}.
However, it may be better to just leave it as a factor, depending upon
what you intend to do with it later.
Hope this helps.
Regards,
Mike
On 10/23/06, Kim Milferstedt <milferst at uiuc.edu>
wrote:> Hello,
>
> in the data.frame "resultsfuzzy" I would like to replace the
> characters in the second column ("5a", "5b", ...
"5e") with numbers
> from 1 to 5. The data.frame has 39150 entries. I seems to work on
> samples that are << nrow(resultsfuzzy) but it takes suspicously long.
>
> Do you have any suggestions how to make the character replacing more
efficient?
>
> Code:
>
> for (i in 1:nrow(resultsfuzzy))
> {
> if (resultsfuzzy[i,2] == "5a"){resultsfuzzy[i,2] <- 1} else
> if (resultsfuzzy[i,2] == "5b"){resultsfuzzy[i,2] <- 2}
else
> if (resultsfuzzy[i,2] == "5c"){resultsfuzzy[i,2] <-
3} else
> if (resultsfuzzy[i,2] == "5d"){resultsfuzzy[i,2]
<- 4} else
> resultsfuzzy[i,2] <- 5
> }
>
> Thanks,
>
> Kim
>
> version
>
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 2.1
> year 2005
> month 12
> day 20
> svn rev 36812
> language R
>
> __________________________________________
>
> Kim Milferstedt
> University of Illinois at Urbana-Champaign
> Department of Civil and Environmental Engineering
> 4125 Newmark Civil Engineering Laboratory
> 205 North Mathews Avenue MC-250
> Urbana, IL 61801
> USA
> phone: (001) 217 333-9663
> fax: (001) 217 333-6968
> email: milferst at uiuc.edu
> http://cee.uiuc.edu/research/morgenroth
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Regards,
Mike Nielsen
On 10/23/2006 6:03 PM, Kim Milferstedt wrote:> Hello, > > in the data.frame "resultsfuzzy" I would like to replace the > characters in the second column ("5a", "5b", ... "5e") with numbers > from 1 to 5. The data.frame has 39150 entries. I seems to work on > samples that are << nrow(resultsfuzzy) but it takes suspicously long. > > Do you have any suggestions how to make the character replacing more efficient?I don't know if nested if/else is inefficient, but indexing of data.frames certainly is. You would do a lot better with ifelse() on the whole column. For example, if column 2 is named B, this would be much faster: resultsfuzzy$B <- ifelse(resultsfuzzy$B == "5a", 1, ifelse(resultsfuzzy$B == "5b", 2, ... )) (where you'll have to fill in the ... yourself in the obvious way. But an even faster way for your particular problem would be resultsfuzzy$B <- match(resultsfuzzy$B, c("5a", "5b", "5c", "5d", "5e")) Duncan Murdoch> > Code: > > for (i in 1:nrow(resultsfuzzy)) > { > if (resultsfuzzy[i,2] == "5a"){resultsfuzzy[i,2] <- 1} else > if (resultsfuzzy[i,2] == "5b"){resultsfuzzy[i,2] <- 2} else > if (resultsfuzzy[i,2] == "5c"){resultsfuzzy[i,2] <- 3} else > if (resultsfuzzy[i,2] == "5d"){resultsfuzzy[i,2] <- 4} else > resultsfuzzy[i,2] <- 5 > } > > Thanks, > > Kim > > version > > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 2.1 > year 2005 > month 12 > day 20 > svn rev 36812 > language R > > __________________________________________ > > Kim Milferstedt > University of Illinois at Urbana-Champaign > Department of Civil and Environmental Engineering > 4125 Newmark Civil Engineering Laboratory > 205 North Mathews Avenue MC-250 > Urbana, IL 61801 > USA > phone: (001) 217 333-9663 > fax: (001) 217 333-6968 > email: milferst at uiuc.edu > http://cee.uiuc.edu/research/morgenroth > > ______________________________________________ > R-help at stat.math.ethz.ch 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.
There are a number of ways this might be approached. Can you please give a sample of your data, and your desired output? Are "5a" ... "5e" the only values that appear in that column, or are there other values, "4e" for instance, that should stay the same during your conversion? Do you wish to use the numbers 1 to 5 in the processed column in arithmetic processing, or are they just an enumeration of possible values? While you think about it, I direct your attention to the functions: sub factor -Alex On 23 Oct 2006, at 23:03, Kim Milferstedt wrote:> Hello, > > in the data.frame "resultsfuzzy" I would like to replace the > characters in the second column ("5a", "5b", ... "5e") with numbers > from 1 to 5. The data.frame has 39150 entries. I seems to work on > samples that are << nrow(resultsfuzzy) but it takes suspicously long. > > Do you have any suggestions how to make the character replacing > more efficient? > > Code: > > for (i in 1:nrow(resultsfuzzy)) > { > if (resultsfuzzy[i,2] == "5a"){resultsfuzzy[i,2] <- 1} else > if (resultsfuzzy[i,2] == "5b"){resultsfuzzy[i,2] <- 2} else > if (resultsfuzzy[i,2] == "5c"){resultsfuzzy[i,2] <- 3} else > if (resultsfuzzy[i,2] == "5d"){resultsfuzzy[i,2] <- 4} > else > resultsfuzzy[i,2] <- 5 > } > > Thanks, > > Kim > > version > > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 2.1 > year 2005 > month 12 > day 20 > svn rev 36812 > language R > > __________________________________________ > > Kim Milferstedt > University of Illinois at Urbana-Champaign > Department of Civil and Environmental Engineering > 4125 Newmark Civil Engineering Laboratory > 205 North Mathews Avenue MC-250 > Urbana, IL 61801 > USA > phone: (001) 217 333-9663 > fax: (001) 217 333-6968 > email: milferst at uiuc.edu > http://cee.uiuc.edu/research/morgenroth > > ______________________________________________ > R-help at stat.math.ethz.ch 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.
Hi Alex, find below a sample of the input and the desired output of my data. 5a ... 5e are indeed the only possible values for the column in question. I would like to replace 5a --> 1, 55b --> 2, ... 5e --> 5. Kim ## input ### Image_ID Class Max 1 2 3 4 5 exp 060901_1545_17_1_10.tif 5c 0.82329 0.32734 0.12593 0.50405 0.03987 0.00282 1.7 060902_1570_01_1_01.tif 5a 0.65336 0.59857 0.10341 0.25193 0.04384 0.00225 1.7 060902_1570_01_1_02.tif 5c 0.57736 0.22884 0.08554 0.65148 0.03091 0.00323 1.7 060902_1570_01_1_03.tif 5a 0.28857 0.83517 0.02118 0.12374 0.018 0.00191 1.7 060902_1570_01_1_04.tif 5b 0.58386 0.12772 0.60949 0.19336 0.06501 0.00442 1.7 060902_1570_01_1_05.tif 5c 0.83419 0.3594 0.08062 0.5252 0.03211 0.00267 1.7 060902_1570_01_1_06.tif 5c 0.61535 0.27652 0.04082 0.66117 0.01933 0.00217 1.7 060902_1570_01_1_07.tif 5c 0.22709 0.0969 0.02196 0.86981 0.00985 0.00149 1.7 060902_1570_01_1_08.tif 5c 0.24596 0.10647 0.02151 0.86051 0.01 0.00151 1.7 060902_1570_01_1_09.tif 5a 0.92945 0.48802 0.04582 0.41747 0.03852 0.01017 1.7 060902_1570_01_1_10.tif 5a 0.49169 0.71852 0.03417 0.2102 0.03203 0.00508 1.7 060902_1570_06_1_01.tif 5b 0.1927 0.05284 0.86286 0.02789 0.05556 0.00085 1.7 060902_1570_06_1_02.tif 5a 0.12993 0.91879 0.01481 0.04872 0.01643 0.00125 1.7 ## output ### Image_ID Class Max 1 2 3 4 5 exp 060901_1545_17_1_10.tif 3 0.82329 0.32734 0.12593 0.50405 0.03987 0.00282 1.7 060902_1570_01_1_01.tif 1 0.65336 0.59857 0.10341 0.25193 0.04384 0.00225 1.7 060902_1570_01_1_02.tif 3 0.57736 0.22884 0.08554 0.65148 0.03091 0.00323 1.7 060902_1570_01_1_03.tif 1 0.28857 0.83517 0.02118 0.12374 0.018 0.00191 1.7 060902_1570_01_1_04.tif 2 0.58386 0.12772 0.60949 0.19336 0.06501 0.00442 1.7 060902_1570_01_1_05.tif 3 0.83419 0.3594 0.08062 0.5252 0.03211 0.00267 1.7 060902_1570_01_1_06.tif 3 0.61535 0.27652 0.04082 0.66117 0.01933 0.00217 1.7 060902_1570_01_1_07.tif 3 0.22709 0.0969 0.02196 0.86981 0.00985 0.00149 1.7 060902_1570_01_1_08.tif 3 0.24596 0.10647 0.02151 0.86051 0.01 0.00151 1.7 060902_1570_01_1_09.tif 1 0.92945 0.48802 0.04582 0.41747 0.03852 0.01017 1.7 060902_1570_01_1_10.tif 1 0.49169 0.71852 0.03417 0.2102 0.03203 0.00508 1.7 060902_1570_06_1_01.tif 2 0.1927 0.05284 0.86286 0.02789 0.05556 0.00085 1.7 060902_1570_06_1_02.tif 1 0.12993 0.91879 0.01481 0.04872 0.01643 0.00125 1.7 At 17:23 06/10/23, you wrote:>There are a number of ways this might be approached. > >Can you please give a sample of your data, and your desired output? > >Are "5a" ... "5e" the only values that appear in that column, or are >there other values, "4e" for instance, that should stay the same >during your conversion? > >Do you wish to use the numbers 1 to 5 in the processed column in >arithmetic processing, or are they just an enumeration of possible >values? > >While you think about it, I direct your attention to the functions: > >sub >factor > >-Alex > >On 23 Oct 2006, at 23:03, Kim Milferstedt wrote: > >>Hello, >> >>in the data.frame "resultsfuzzy" I would like to replace the >>characters in the second column ("5a", "5b", ... "5e") with numbers >>from 1 to 5. The data.frame has 39150 entries. I seems to work on >>samples that are << nrow(resultsfuzzy) but it takes suspicously long. >> >>Do you have any suggestions how to make the character replacing >>more efficient? >> >>Code: >> >>for (i in 1:nrow(resultsfuzzy)) >>{ >>if (resultsfuzzy[i,2] == "5a"){resultsfuzzy[i,2] <- 1} else >> if (resultsfuzzy[i,2] == "5b"){resultsfuzzy[i,2] <- 2} else >> if (resultsfuzzy[i,2] == "5c"){resultsfuzzy[i,2] <- 3} else >> if (resultsfuzzy[i,2] == "5d"){resultsfuzzy[i,2] <- 4} >>else >> resultsfuzzy[i,2] <- 5 >>} >> >>Thanks, >> >>Kim >> >>version >> >>platform i386-pc-mingw32 >>arch i386 >>os mingw32 >>system i386, mingw32 >>status >>major 2 >>minor 2.1 >>year 2005 >>month 12 >>day 20 >>svn rev 36812 >>language R >> >>__________________________________________ >> >>Kim Milferstedt >>University of Illinois at Urbana-Champaign >>Department of Civil and Environmental Engineering >>4125 Newmark Civil Engineering Laboratory >>205 North Mathews Avenue MC-250 >>Urbana, IL 61801 >>USA >>phone: (001) 217 333-9663 >>fax: (001) 217 333-6968 >>email: milferst at uiuc.edu >>http://cee.uiuc.edu/research/morgenroth >> >>______________________________________________ >>R-help at stat.math.ethz.ch 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 I get it right (data are not well aligned!) these are values in Class column.
Right?
Than Class = as.numeric(factor(Class))
should work
Stefano
On Tue, Oct 24, 2006 at 08:20:08AM -0500, Kim Milferstedt wrote:
<Kim>Hi Alex,
<Kim>
<Kim>find below a sample of the input and the desired output of my data.
<Kim>5a ... 5e are indeed the only possible values for the column in
<Kim>question. I would like to replace 5a --> 1, 55b --> 2, ... 5e
--> 5.
<Kim>
<Kim>Kim
<Kim>
<Kim>## input ###
<Kim>
<Kim>Image_ID Class Max 1 2 3
<Kim> 4 5 exp
<Kim>060901_1545_17_1_10.tif 5c 0.82329 0.32734 0.12593 0.50405
<Kim>0.03987 0.00282 1.7
<Kim>060902_1570_01_1_01.tif 5a 0.65336 0.59857 0.10341 0.25193
<Kim>0.04384 0.00225 1.7
<Kim>060902_1570_01_1_02.tif 5c 0.57736 0.22884 0.08554 0.65148
<Kim>0.03091 0.00323 1.7
<Kim>060902_1570_01_1_03.tif 5a 0.28857 0.83517 0.02118 0.12374
<Kim>0.018 0.00191 1.7
<Kim>060902_1570_01_1_04.tif 5b 0.58386 0.12772 0.60949 0.19336
<Kim>0.06501 0.00442 1.7
<Kim>060902_1570_01_1_05.tif 5c 0.83419 0.3594 0.08062
<Kim>0.5252 0.03211 0.00267 1.7
<Kim>060902_1570_01_1_06.tif 5c 0.61535 0.27652 0.04082 0.66117
<Kim>0.01933 0.00217 1.7
<Kim>060902_1570_01_1_07.tif 5c 0.22709 0.0969 0.02196 0.86981
<Kim>0.00985 0.00149 1.7
<Kim>060902_1570_01_1_08.tif 5c 0.24596 0.10647 0.02151 0.86051
<Kim>0.01 0.00151 1.7
<Kim>060902_1570_01_1_09.tif 5a 0.92945 0.48802 0.04582 0.41747
<Kim>0.03852 0.01017 1.7
<Kim>060902_1570_01_1_10.tif 5a 0.49169 0.71852 0.03417
<Kim>0.2102 0.03203 0.00508 1.7
<Kim>060902_1570_06_1_01.tif 5b 0.1927 0.05284 0.86286 0.02789
<Kim>0.05556 0.00085 1.7
<Kim>060902_1570_06_1_02.tif 5a 0.12993 0.91879 0.01481 0.04872
<Kim>0.01643 0.00125 1.7
<Kim>
<Kim>## output ###
<Kim>
<Kim>Image_ID Class Max 1 2 3
<Kim> 4 5 exp
<Kim>060901_1545_17_1_10.tif 3 0.82329 0.32734 0.12593 0.50405
<Kim>0.03987 0.00282 1.7
<Kim>060902_1570_01_1_01.tif 1 0.65336 0.59857 0.10341 0.25193
<Kim>0.04384 0.00225 1.7
<Kim>060902_1570_01_1_02.tif 3 0.57736 0.22884 0.08554 0.65148
<Kim>0.03091 0.00323 1.7
<Kim>060902_1570_01_1_03.tif 1 0.28857 0.83517 0.02118 0.12374
<Kim>0.018 0.00191 1.7
<Kim>060902_1570_01_1_04.tif 2 0.58386 0.12772 0.60949 0.19336
<Kim>0.06501 0.00442 1.7
<Kim>060902_1570_01_1_05.tif 3 0.83419 0.3594 0.08062
<Kim>0.5252 0.03211 0.00267 1.7
<Kim>060902_1570_01_1_06.tif 3 0.61535 0.27652 0.04082 0.66117
<Kim>0.01933 0.00217 1.7
<Kim>060902_1570_01_1_07.tif 3 0.22709 0.0969 0.02196 0.86981
<Kim>0.00985 0.00149 1.7
<Kim>060902_1570_01_1_08.tif 3 0.24596 0.10647 0.02151 0.86051
<Kim>0.01 0.00151 1.7
<Kim>060902_1570_01_1_09.tif 1 0.92945 0.48802 0.04582 0.41747
<Kim>0.03852 0.01017 1.7
<Kim>060902_1570_01_1_10.tif 1 0.49169 0.71852 0.03417
<Kim>0.2102 0.03203 0.00508 1.7
<Kim>060902_1570_06_1_01.tif 2 0.1927 0.05284 0.86286 0.02789
<Kim>0.05556 0.00085 1.7
<Kim>060902_1570_06_1_02.tif 1 0.12993 0.91879 0.01481 0.04872
<Kim>0.01643 0.00125 1.7
<Kim>
<Kim>
<Kim>At 17:23 06/10/23, you wrote:
<Kim>>There are a number of ways this might be approached.
<Kim>>
<Kim>>Can you please give a sample of your data, and your desired
output?
<Kim>>
<Kim>>Are "5a" ... "5e" the only values that appear
in that column, or are
<Kim>>there other values, "4e" for instance, that should stay
the same
<Kim>>during your conversion?
<Kim>>
<Kim>>Do you wish to use the numbers 1 to 5 in the processed column in
<Kim>>arithmetic processing, or are they just an enumeration of
possible
<Kim>>values?
<Kim>>
<Kim>>While you think about it, I direct your attention to the
functions:
<Kim>>
<Kim>>sub
<Kim>>factor
<Kim>>
<Kim>>-Alex
<Kim>>
<Kim>>On 23 Oct 2006, at 23:03, Kim Milferstedt wrote:
<Kim>>
<Kim>>>Hello,
<Kim>>>
<Kim>>>in the data.frame "resultsfuzzy" I would like to
replace the
<Kim>>>characters in the second column ("5a",
"5b", ... "5e") with numbers
<Kim>>>from 1 to 5. The data.frame has 39150 entries. I seems to
work on
<Kim>>>samples that are << nrow(resultsfuzzy) but it takes
suspicously long.
<Kim>>>
<Kim>>>Do you have any suggestions how to make the character
replacing
<Kim>>>more efficient?
<Kim>>>
<Kim>>>Code:
<Kim>>>
<Kim>>>for (i in 1:nrow(resultsfuzzy))
<Kim>>>{
<Kim>>>if (resultsfuzzy[i,2] == "5a"){resultsfuzzy[i,2]
<- 1} else
<Kim>>> if (resultsfuzzy[i,2] ==
"5b"){resultsfuzzy[i,2] <- 2} else
<Kim>>> if (resultsfuzzy[i,2] ==
"5c"){resultsfuzzy[i,2] <- 3} else
<Kim>>> if (resultsfuzzy[i,2] ==
"5d"){resultsfuzzy[i,2] <- 4}
<Kim>>>else
<Kim>>> resultsfuzzy[i,2] <- 5
<Kim>>>}
<Kim>>>
<Kim>>>Thanks,
<Kim>>>
<Kim>>>Kim
<Kim>>>
<Kim>>>version
<Kim>>>
<Kim>>>platform i386-pc-mingw32
<Kim>>>arch i386
<Kim>>>os mingw32
<Kim>>>system i386, mingw32
<Kim>>>status
<Kim>>>major 2
<Kim>>>minor 2.1
<Kim>>>year 2005
<Kim>>>month 12
<Kim>>>day 20
<Kim>>>svn rev 36812
<Kim>>>language R
<Kim>>>
<Kim>>>__________________________________________
<Kim>>>
<Kim>>>Kim Milferstedt
<Kim>>>University of Illinois at Urbana-Champaign
<Kim>>>Department of Civil and Environmental Engineering
<Kim>>>4125 Newmark Civil Engineering Laboratory
<Kim>>>205 North Mathews Avenue MC-250
<Kim>>>Urbana, IL 61801
<Kim>>>USA
<Kim>>>phone: (001) 217 333-9663
<Kim>>>fax: (001) 217 333-6968
<Kim>>>email: milferst a uiuc.edu
<Kim>>>http://cee.uiuc.edu/research/morgenroth
<Kim>>>
<Kim>>>______________________________________________
<Kim>>>R-help a stat.math.ethz.ch mailing list
<Kim>>>https://stat.ethz.ch/mailman/listinfo/r-help
<Kim>>>PLEASE do read the posting guide
http://www.R-project.org/posting- guide.html
<Kim>>>and provide commented, minimal, self-contained, reproducible
code.
<Kim>
<Kim>______________________________________________
<Kim>R-help a stat.math.ethz.ch mailing list
<Kim>https://stat.ethz.ch/mailman/listinfo/r-help
<Kim>PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
<Kim>and provide commented, minimal, self-contained, reproducible code.
Hi so probably easiest approach is input$Class<-as.numeric(input$Class) if input$Class is factor, what can be tested e.g. by str(input) HTH Petr On 24 Oct 2006 at 8:20, Kim Milferstedt wrote: Date sent: Tue, 24 Oct 2006 08:20:08 -0500 To: r-help at stat.math.ethz.ch From: Kim Milferstedt <milferst at uiuc.edu> Subject: Re: [R] nested if/else very slow, more efficient ways?> Hi Alex, > > find below a sample of the input and the desired output of my data. 5a > ... 5e are indeed the only possible values for the column in question. > I would like to replace 5a --> 1, 55b --> 2, ... 5e --> 5. > > Kim > > ## input ### > > Image_ID Class Max 1 2 3 > 4 5 exp > 060901_1545_17_1_10.tif 5c 0.82329 0.32734 0.12593 0.50405 > 0.03987 0.00282 1.7 > 060902_1570_01_1_01.tif 5a 0.65336 0.59857 0.10341 0.25193 > 0.04384 0.00225 1.7 > 060902_1570_01_1_02.tif 5c 0.57736 0.22884 0.08554 0.65148 > 0.03091 0.00323 1.7 > 060902_1570_01_1_03.tif 5a 0.28857 0.83517 0.02118 0.12374 > 0.018 0.00191 1.7 > 060902_1570_01_1_04.tif 5b 0.58386 0.12772 0.60949 0.19336 > 0.06501 0.00442 1.7 > 060902_1570_01_1_05.tif 5c 0.83419 0.3594 0.08062 > 0.5252 0.03211 0.00267 1.7 > 060902_1570_01_1_06.tif 5c 0.61535 0.27652 0.04082 0.66117 > 0.01933 0.00217 1.7 > 060902_1570_01_1_07.tif 5c 0.22709 0.0969 0.02196 0.86981 > 0.00985 0.00149 1.7 > 060902_1570_01_1_08.tif 5c 0.24596 0.10647 0.02151 0.86051 > 0.01 0.00151 1.7 > 060902_1570_01_1_09.tif 5a 0.92945 0.48802 0.04582 0.41747 > 0.03852 0.01017 1.7 > 060902_1570_01_1_10.tif 5a 0.49169 0.71852 0.03417 > 0.2102 0.03203 0.00508 1.7 > 060902_1570_06_1_01.tif 5b 0.1927 0.05284 0.86286 0.02789 > 0.05556 0.00085 1.7 > 060902_1570_06_1_02.tif 5a 0.12993 0.91879 0.01481 0.04872 > 0.01643 0.00125 1.7 > > ## output ### > > Image_ID Class Max 1 2 3 > 4 5 exp > 060901_1545_17_1_10.tif 3 0.82329 0.32734 0.12593 0.50405 > 0.03987 0.00282 1.7 > 060902_1570_01_1_01.tif 1 0.65336 0.59857 0.10341 0.25193 > 0.04384 0.00225 1.7 > 060902_1570_01_1_02.tif 3 0.57736 0.22884 0.08554 0.65148 > 0.03091 0.00323 1.7 > 060902_1570_01_1_03.tif 1 0.28857 0.83517 0.02118 0.12374 > 0.018 0.00191 1.7 > 060902_1570_01_1_04.tif 2 0.58386 0.12772 0.60949 0.19336 > 0.06501 0.00442 1.7 > 060902_1570_01_1_05.tif 3 0.83419 0.3594 0.08062 > 0.5252 0.03211 0.00267 1.7 > 060902_1570_01_1_06.tif 3 0.61535 0.27652 0.04082 0.66117 > 0.01933 0.00217 1.7 > 060902_1570_01_1_07.tif 3 0.22709 0.0969 0.02196 0.86981 > 0.00985 0.00149 1.7 > 060902_1570_01_1_08.tif 3 0.24596 0.10647 0.02151 0.86051 > 0.01 0.00151 1.7 > 060902_1570_01_1_09.tif 1 0.92945 0.48802 0.04582 0.41747 > 0.03852 0.01017 1.7 > 060902_1570_01_1_10.tif 1 0.49169 0.71852 0.03417 > 0.2102 0.03203 0.00508 1.7 > 060902_1570_06_1_01.tif 2 0.1927 0.05284 0.86286 0.02789 > 0.05556 0.00085 1.7 > 060902_1570_06_1_02.tif 1 0.12993 0.91879 0.01481 0.04872 > 0.01643 0.00125 1.7 > > > At 17:23 06/10/23, you wrote: > >There are a number of ways this might be approached. > > > >Can you please give a sample of your data, and your desired output? > > > >Are "5a" ... "5e" the only values that appear in that column, or are > >there other values, "4e" for instance, that should stay the same > >during your conversion? > > > >Do you wish to use the numbers 1 to 5 in the processed column in > >arithmetic processing, or are they just an enumeration of possible > >values? > > > >While you think about it, I direct your attention to the functions: > > > >sub > >factor > > > >-Alex > > > >On 23 Oct 2006, at 23:03, Kim Milferstedt wrote: > > > >>Hello, > >> > >>in the data.frame "resultsfuzzy" I would like to replace the > >>characters in the second column ("5a", "5b", ... "5e") with numbers > >>from 1 to 5. The data.frame has 39150 entries. I seems to work on > >>samples that are << nrow(resultsfuzzy) but it takes suspicously > >>long. > >> > >>Do you have any suggestions how to make the character replacing more > >>efficient? > >> > >>Code: > >> > >>for (i in 1:nrow(resultsfuzzy)) > >>{ > >>if (resultsfuzzy[i,2] == "5a"){resultsfuzzy[i,2] <- 1} else > >> if (resultsfuzzy[i,2] == "5b"){resultsfuzzy[i,2] <- 2} else > >> if (resultsfuzzy[i,2] == "5c"){resultsfuzzy[i,2] <- 3} > >> else > >> if (resultsfuzzy[i,2] == "5d"){resultsfuzzy[i,2] <- 4} > >>else > >> resultsfuzzy[i,2] <- 5 > >>} > >> > >>Thanks, > >> > >>Kim > >> > >>version > >> > >>platform i386-pc-mingw32 > >>arch i386 > >>os mingw32 > >>system i386, mingw32 > >>status > >>major 2 > >>minor 2.1 > >>year 2005 > >>month 12 > >>day 20 > >>svn rev 36812 > >>language R > >> > >>__________________________________________ > >> > >>Kim Milferstedt > >>University of Illinois at Urbana-Champaign > >>Department of Civil and Environmental Engineering > >>4125 Newmark Civil Engineering Laboratory > >>205 North Mathews Avenue MC-250 > >>Urbana, IL 61801 > >>USA > >>phone: (001) 217 333-9663 > >>fax: (001) 217 333-6968 > >>email: milferst at uiuc.edu > >>http://cee.uiuc.edu/research/morgenroth > >> > >>______________________________________________ > >>R-help at stat.math.ethz.ch 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 at stat.math.ethz.ch 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.Petr Pikal petr.pikal at precheza.cz
Seemingly Similar Threads
- R for copying and pasting selected image files?
- removing a specific number of digist from a character string
- update index in "for" statement during calculation
- barplot with different color combination for each bar
- which points within an ellipsoid? Sorting data in 3d