Hi Friends,
I'm new to R ,I have a data frame Z16 which is genarated from another data
frame, and I want to add ?%? & ?$? in row 4 and 5 respectively. when I?m
trying using below logic, I?m getting warning message. I'm using R 2.14.2
Version
Can anyone help me out on this.
Note: Initially i used tranfrom function to do some calculations,where ever
it should give zero,its giving NaN,i used Replace function to replace NaN
with Zero(0)
Z16:
Summary G Y R T
Accts 582 644 0 1226
AcctCov 230 165 0 395
Cov% 40 26 0 32
UnCov% 60 74 0 68
EqVol11$MM 8.5 10.6 0 19.1
Using this logic:
Z16[5,2:5]<-paste("$",Z16[5,2:5],sep="")
Z16[3,2:5]<-paste(Z16[3,2:5],"%",sep="")
Z16[4,2:5]<-paste(Z16[4,2:5],"%",sep="")
Getting this Warning: In `[<-.factor`(`*tmp*`, iseq, value = c(3L, 1L, 2L,
4L, NA))
invalid factor level, NAs
generate
Final result:
Summary G Y R T
Accts 582 644 0 1226
AcctCov 230 165 0 395
Cov% 40% 26% 0% 32%
UnCov% 60% 74% 0% 68%
EqVol11$MM $8.50 $10.60 $0 $19.10
Thanks in Advance.
Thanks,
Namit
--
View this message in context:
http://r.789695.n4.nabble.com/Can-any-one-help-me-on-this-Issue-tp4638664.html
Sent from the R help mailing list archive at Nabble.com.
Hi,
I am trying to follow the same logic starting from the initial dataset with NaN.
Z16<-read.table(text="
Summary ? ? ? ? ? ?G ? ? ? Y ? ? ? ?R ? ? ? ?T
Accts ? ? ? ? ? ? ? ? ? 582 ? ?644 ? ?NaN ? ? ? ?1226
AcctCov ? ? ? ? ? ? 230 ? ?165 ? ?NaN ? ? ? ?395
Cov% ? ? ? ? ? ? ? ? ? ?40 ? ? 26 ? ? ?NaN ? ? ? ?32
UnCov% ? ? ? ? ? ? ?60 ? ? 74 ? ? ?NaN ? ? ? ?68
EqVol11$MM ? ?8.5 ? 10.6 ? ?NaN ? ? ? 19.1
",sep="",header=TRUE,stringsAsFactors=FALSE)
?Z16$R[is.nan(Z16$R)]<-0
str(Z16)
#'data.frame': 5 obs. of ?5 variables:
?#$ Summary: chr ?"Accts" "AcctCov" "Cov%"
"UnCov%" ...
?#$ G ? ? ?: num ?582 230 40 60 8.5
?#$ Y ? ? ?: num ?644 165 26 74 10.6
?#$ R ? ? ?: num ?0 0 0 0 0
?#$ T ? ? ?: num ?1226 395 32 68 19.1
Z16[5,2:5]<-paste("$",Z16[5,2:5],sep="")
?Z16[3,2:5]<-paste(Z16[3,2:5],"%",sep="")
?Z16[4,2:5]<-paste(Z16[4,2:5],"%",sep="")
?Z16
# ? ? Summary ? ?G ? ? Y ?R ? ? T
#1 ? ? ?Accts ?582 ? 644 ?0 ?1226
#2 ? ?AcctCov ?230 ? 165 ?0 ? 395
#3 ? ? ? Cov% ?40% ? 26% 0% ? 32%
#4 ? ? UnCov% ?60% ? 74% 0% ? 68%
#5 EqVol11$MM $8.5 $10.6 $0 $19.1
As I mentioned earlier, check str(), use stringsAsFactors=FALSE in read.table().
?Not sure if R 2.14.2 version is the problem.?
A.K.
----- Original Message -----
From: namit <saileshchowdary at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Wednesday, August 1, 2012 8:51 AM
Subject: [R] Can any one help me on this Issue
Hi Friends,
I'm new to R ,I? have? a data frame Z16 which is genarated from another data
frame, and I want to add ?%? & ?$? in row? 4 and 5 respectively. when I?m
trying using below logic, I?m getting warning message. I'm using R 2.14.2
Version
Can anyone? help me out on this.
Note: Initially i used tranfrom function to do some calculations,where ever
it should give zero,its giving NaN,i used Replace function to replace NaN
with Zero(0)
Z16:
Summary? ? ? ? ? ? G? ? ? Y? ? ? ? R? ? ? ? T
Accts? ? ? ? ? ? ? ? ? 582? ? 644? ? 0? ? ? ? 1226
AcctCov? ? ? ? ? ? 230? ? 165? ? 0? ? ? ? 395
Cov%? ? ? ? ? ? ? ? ? ? 40? ? 26? ? ? 0? ? ? ? 32
UnCov%? ? ? ? ? ? ? 60? ? 74? ? ? 0? ? ? ? 68
EqVol11$MM? ? 8.5? 10.6? ? 0? ? ? ? 19.1
Using this logic:
Z16[5,2:5]<-paste("$",Z16[5,2:5],sep="")
Z16[3,2:5]<-paste(Z16[3,2:5],"%",sep="")
Z16[4,2:5]<-paste(Z16[4,2:5],"%",sep="")
Getting this Warning: In `[<-.factor`(`*tmp*`, iseq, value = c(3L, 1L, 2L,
4L, NA))
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? invalid factor level, NAs
generate
Final result:
Summary? ? ? ? ? ? ? G? ? ? ? Y? ? ? ? ? ? R? ? ? ? T
Accts? ? ? ? ? ? ? ? ? ? ? 582? ? ? 644? ? ? ? 0? ? ? ? 1226
AcctCov? ? ? ? ? ? ? ? 230? ? ? 165? ? ? ? 0? ? ? ? 395
Cov%? ? ? ? ? ? ? ? ? ? 40%? ? ? 26%? ? ? ? 0%? ? 32%
UnCov%? ? ? ? ? ? ? 60%? ? ? 74%? ? ? 0%? ? 68%
EqVol11$MM? ? $8.50? $10.60? ? $0? ? ? $19.10
Thanks in Advance.
Thanks,
Namit
--
View this message in context:
http://r.789695.n4.nabble.com/Can-any-one-help-me-on-this-Issue-tp4638664.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Hi Namit, I feel like you posted this (or a _very_ similar) question just a few days ago: yes.... indeed you did: https://stat.ethz.ch/pipermail/r-help/2012-July/319634.html with a good amount of response. I'm going to direct you in a different path: don't add these things within R, at least, not to the very end. Your numbers are truly just numbers; dollar signs and percent symbols are just typographical cruft that humans like to see -- not computationally relevant, but admittedly quite useful -- so add them on in making your final report (in Sweave / LaTeX or other) Your upstream problems seems to be that you have factors and not numbers in your data frame. You'd be better served trying to find the cause of that -- str() is helpful -- and, if you can fix that, all your warning message should take care of themselves. Best, Michael On Wed, Aug 1, 2012 at 7:51 AM, namit <saileshchowdary at gmail.com> wrote:> Hi Friends, > > > I'm new to R ,I have a data frame Z16 which is genarated from another data > frame, and I want to add ?%? & ?$? in row 4 and 5 respectively. when I?m > trying using below logic, I?m getting warning message. I'm using R 2.14.2 > Version > Can anyone help me out on this. > > Note: Initially i used tranfrom function to do some calculations,where ever > it should give zero,its giving NaN,i used Replace function to replace NaN > with Zero(0) > > Z16: > Summary G Y R T > Accts 582 644 0 1226 > AcctCov 230 165 0 395 > Cov% 40 26 0 32 > UnCov% 60 74 0 68 > EqVol11$MM 8.5 10.6 0 19.1 > > Using this logic: > > Z16[5,2:5]<-paste("$",Z16[5,2:5],sep="") > Z16[3,2:5]<-paste(Z16[3,2:5],"%",sep="") > Z16[4,2:5]<-paste(Z16[4,2:5],"%",sep="") > > Getting this Warning: In `[<-.factor`(`*tmp*`, iseq, value = c(3L, 1L, 2L, > 4L, NA)) > invalid factor level, NAs > generate > > > Final result: > > Summary G Y R T > Accts 582 644 0 1226 > AcctCov 230 165 0 395 > Cov% 40% 26% 0% 32% > UnCov% 60% 74% 0% 68% > EqVol11$MM $8.50 $10.60 $0 $19.10 > > Thanks in Advance. > > Thanks, > Namit > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Can-any-one-help-me-on-this-Issue-tp4638664.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.