[R] Can any one help me on this Issue

jim holtman jholtman at gmail.com
Thu Aug 2 04:36:43 CEST 2012


Seems to work fine under 2.15.1


R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Loading required package: graphics
The following object(s) are masked from 'package:base':

    setwd
##-- startup:  Thu Jul 26 21:03:55 2012 ------##
> x <- scan(text = "19.2
+ 18
+ 18.8
+ 7.5
+ 14.9
+ 12.4
+ 18.3
+ 16.2
+ 2
+ 3.8
+ 4.2
+ 4.5
+ 11.4
+ 16.9
+ 3.9
+ 3.9
+ 7.7
+ 4
+ 4.1
+ 4.3", what = 0)
Read 20 items
> x
 [1] 19.2 18.0 18.8  7.5 14.9 12.4 18.3 16.2  2.0  3.8  4.2  4.5 11.4
16.9  3.9  3.9  7.7  4.0  4.1  4.3
> my.func(x)
     Count       Mean         SD        Min     Median        90%
  95%        Max        Sum
 20.000000   9.800000   6.355851   2.000000   7.600000  18.350000
18.820000  19.200000 196.000000
> 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
> #'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
> #     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
>
>


On Wed, Aug 1, 2012 at 6:23 PM, arun <smartpink111 at yahoo.com> wrote:
> 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.
>
>
> ______________________________________________
> 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list