how to replace <NA> values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

how to replace <NA> values

kingsly
Dear R community
 
I have a large data set contain some empty cells. Because of that,  may be I am wrong, <NA> values are produced.
Now I want replace both empty and <NA> values with zero.
 
Elder1 <- data.frame(
  ID=c("ID1","ID2","ID3","ID6","ID8"),
  age=c(38,35,"",NA,NA))
Output I am expecting
 
ID   age
ID1  38
ID2  35
ID3  0
ID6  0
ID8  0
 
In advance I thank your help.
Reply | Threaded
Open this post in threaded view
|

Re: how to replace <NA> values

Kehl Dániel
Dear Kinsly,

try http://bit.ly/1mhXOfH

Although values are usually missing for some good reason. Changing them to 0 might be very dangerous, R is going to think that ID3, 6 and 8 are all newborn babies!

best
daniel
________________________________________
Feladó: [hidden email] [[hidden email]] ; meghatalmaz&#243;: kingsly [[hidden email]]
Küldve: 2014. január 19. 20:39
To: [hidden email]
Tárgy: [R] how to replace <NA> values

Dear R community

I have a large data set contain some empty cells. Because of that,  may be I am wrong, <NA> values are produced.
Now I want replace both empty and <NA> values with zero.

Elder1 <- data.frame(
  ID=c("ID1","ID2","ID3","ID6","ID8"),
  age=c(38,35,"",NA,NA))
Output I am expecting

ID   age
ID1  38
ID2  35
ID3  0
ID6  0
ID8  0

In advance I thank your help.



--
View this message in context: http://r.789695.n4.nabble.com/how-to-replace-NA-values-tp4683831.html
Sent from the R help mailing list archive at Nabble.com.
        [[alternative HTML version deleted]]


______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: how to replace <NA> values

John Sorkin
In reply to this post by kingsly
I hope the code below will show you how to co what you want to do.
John

Elder1 <- data.frame(
  ID=c("ID1","ID2","ID3","ID6","ID8"),
  age=c(38,35,"",NA,NA))
Elder1
# The age variable is a factor, we want it to be numeric
class(Elder1[,'age'])
# Convert factor to a numeric value.
Elder1$age<-as.numeric(Elder1[,'age'])
# Below you will see how you can test a value to see if it is NA.
is.na(Elder1[,'age'])
# Replace the NA values with a zero.
Elder1[is.na(Elder1[,'age']),"age"]<-0
# The final data frame with NAs replaced by zeros.
Elder1



John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
>>> kingsly <[hidden email]> 01/19/14 3:01 PM >>>
Dear R community
 
I have a large data set contain some empty cells. Because of that,  may be I am wrong, <NA> values are produced.
Now I want replace both empty and <NA> values with zero.
 
Elder1 <- data.frame(
  ID=c("ID1","ID2","ID3","ID6","ID8"),
  age=c(38,35,"",NA,NA))
Output I am expecting
 
ID   age
ID1  38
ID2  35
ID3  0
ID6  0
ID8  0
 
In advance I thank your help.



--
View this message in context: http://r.789695.n4.nabble.com/how-to-replace-NA-values-tp4683831.html
Sent from the R help mailing list archive at Nabble.com.
    [[alternative HTML version deleted]]



Confidentiality Statement:
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information.  Any unauthorized use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Setting up an R server.

John Sorkin
In reply to this post by kingsly
Can someone provide suggestions about how to best set up an R server? I would like to be able to run R on my IPad. It sounds like the only way to do this is to have the IPad access an R server. The server will be at my home, connected to the internet via my cable company (comcast). I don't yet know if the server will be a linux box or a windows box. I would appreciate advice about setting up both kinds of servers.
Thank you,
John

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

Confidentiality Statement:
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information.  Any unauthorized use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: how to replace <NA> values

PIKAL Petr
In reply to this post by John Sorkin
Hi

I believe that it is not what is wanted (if the OP knows exactly what he whants, which I doubt).

your result is

> Elder1
   ID age
1 ID1   3
2 ID2   2
3 ID3   1
4 ID6   0
5 ID8   0
>

however original output shall be

Elder1$age[Elder1$age==""]<-NA
Elder1$age<-as.numeric(as.character(Elder1$age))
Elder1$age[is.na(Elder1$age)]<-0
Elder1
   ID age
1 ID1  38
2 ID2  35
3 ID3   0
4 ID6   0
5 ID8   0
>

It is up to the OP to understand what age = 0 means.

Regards
Petr



> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of John Sorkin
> Sent: Monday, January 20, 2014 3:07 PM
> To: [hidden email]; [hidden email]
> Subject: Re: [R] how to replace <NA> values
>
> I hope the code below will show you how to co what you want to do.
> John
>
> Elder1 <- data.frame(
>   ID=c("ID1","ID2","ID3","ID6","ID8"),
>   age=c(38,35,"",NA,NA))
> Elder1
> # The age variable is a factor, we want it to be numeric
> class(Elder1[,'age'])
> # Convert factor to a numeric value.
> Elder1$age<-as.numeric(Elder1[,'age'])
> # Below you will see how you can test a value to see if it is NA.
> is.na(Elder1[,'age'])
> # Replace the NA values with a zero.
> Elder1[is.na(Elder1[,'age']),"age"]<-0
> # The final data frame with NAs replaced by zeros.
> Elder1
>
>
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street
> GRECC (BT/18/GR) Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
> >>> kingsly <[hidden email]> 01/19/14 3:01 PM >>>
> Dear R community
>
> I have a large data set contain some empty cells. Because of that,  may
> be I am wrong, <NA> values are produced.
> Now I want replace both empty and <NA> values with zero.
>
> Elder1 <- data.frame(
>   ID=c("ID1","ID2","ID3","ID6","ID8"),
>   age=c(38,35,"",NA,NA))
> Output I am expecting
>
> ID   age
> ID1  38
> ID2  35
> ID3  0
> ID6  0
> ID8  0
>
> In advance I thank your help.
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-
> replace-NA-values-tp4683831.html
> Sent from the R help mailing list archive at Nabble.com.
>     [[alternative HTML version deleted]]
>
>
>
> Confidentiality Statement:
> This email message, including any attachments, is for the sole use of
> the intended recipient(s) and may contain confidential and privileged
> information.  Any unauthorized use, disclosure or distribution is
> prohibited.  If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: how to replace <NA> values

arun kirshna
I think this

Elder1$age[Elder1$age==""]<-NA #is not needed

 Elder1$age<-as.numeric(as.character(Elder1$age)) #convert "" to NAs
A.K.


On Monday, January 20, 2014 9:53 AM, PIKAL Petr <[hidden email]> wrote:
Hi

I believe that it is not what is wanted (if the OP knows exactly what he whants, which I doubt).

your result is

> Elder1
   ID age
1 ID1   3
2 ID2   2
3 ID3   1
4 ID6   0
5 ID8   0
>

however original output shall be

Elder1$age[Elder1$age==""]<-NA
Elder1$age<-as.numeric(as.character(Elder1$age))
Elder1$age[is.na(Elder1$age)]<-0
Elder1
   ID age
1 ID1  38
2 ID2  35
3 ID3   0
4 ID6   0
5 ID8   0
>

It is up to the OP to understand what age = 0 means.

Regards
Petr



> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of John Sorkin
> Sent: Monday, January 20, 2014 3:07 PM
> To: [hidden email]; [hidden email]
> Subject: Re: [R] how to replace <NA> values
>
> I hope the code below will show you how to co what you want to do.
> John
>
> Elder1 <- data.frame(
>   ID=c("ID1","ID2","ID3","ID6","ID8"),
>   age=c(38,35,"",NA,NA))
> Elder1
> # The age variable is a factor, we want it to be numeric
> class(Elder1[,'age'])
> # Convert factor to a numeric value.
> Elder1$age<-as.numeric(Elder1[,'age'])
> # Below you will see how you can test a value to see if it is NA.
> is.na(Elder1[,'age'])
> # Replace the NA values with a zero.
> Elder1[is.na(Elder1[,'age']),"age"]<-0
> # The final data frame with NAs replaced by zeros.
> Elder1
>
>
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street
> GRECC (BT/18/GR) Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
> >>> kingsly <[hidden email]> 01/19/14 3:01 PM >>>
> Dear R community
>
> I have a large data set contain some empty cells. Because of that,  may
> be I am wrong, <NA> values are produced.
> Now I want replace both empty and <NA> values with zero.
>
> Elder1 <- data.frame(
>   ID=c("ID1","ID2","ID3","ID6","ID8"),
>   age=c(38,35,"",NA,NA))
> Output I am expecting
>
> ID   age
> ID1  38
> ID2  35
> ID3  0
> ID6  0
> ID8  0
>
> In advance I thank your help.
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-
> replace-NA-values-tp4683831.html
> Sent from the R help mailing list archive at Nabble.com.
>     [[alternative HTML version deleted]]
>
>
>
> Confidentiality Statement:
> This email message, including any attachments, is for the sole use of
> the intended recipient(s) and may contain confidential and privileged
> information.  Any unauthorized use, disclosure or distribution is
> prohibited.  If you are not the intended recipient, please contact the
> sender by reply email and destroy all copies of the original message.

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
______________________________________________
[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.


______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: Setting up an R server.

Michael Weylandt
In reply to this post by John Sorkin
Perhaps http://www.rstudio.com/ide/docs/server/getting_started

Michael

On Mon, Jan 20, 2014 at 9:12 AM, John Sorkin
<[hidden email]> wrote:

> Can someone provide suggestions about how to best set up an R server? I would like to be able to run R on my IPad. It sounds like the only way to do this is to have the IPad access an R server. The server will be at my home, connected to the internet via my cable company (comcast). I don't yet know if the server will be a linux box or a windows box. I would appreciate advice about setting up both kinds of servers.
> Thank you,
> John
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:14}}

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: Setting up an R server.

zadig
In reply to this post by John Sorkin
I didn't try it myself but free Teamviewer software lets you access to any PC linux or windows from your ipad :

http://www.teamviewer.com/


-----Original Message-----
From: "John Sorkin" [[hidden email]]
Date: 01/20/2014 09:13 AM
To: "" <[hidden email]>
Subject: [R] Setting up an R server.

Can someone provide suggestions about how to best set up an R server? I would like to be able to run R on my IPad. It sounds like the only way to do this is to have the IPad access an R server. The server will be at my home, connected to the internet via my cable company (comcast). I don't yet know if the server will be a linux box or a windows box. I would appreciate advice about setting up both kinds of servers.
Thank you,
John

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:7}}

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: how to replace <NA> values

JohnDee
In reply to this post by kingsly
On Sun, 19 Jan 2014 11:39:43 -0800 (PST)
kingsly <[hidden email]> wrote:

> Dear R community
>  
> I have a large data set contain some empty cells. Because of that,
> may be I am wrong, <NA> values are produced. Now I want replace both
> empty and <NA> values with zero.
> Elder1 <- data.frame(
>   ID=c("ID1","ID2","ID3","ID6","ID8"),
>   age=c(38,35,"",NA,NA))
> Output I am expecting
>  
> ID   age
> ID1  38
> ID2  35
> ID3  0
> ID6  0
> ID8  0
>  
> In advance I thank your help.
>
The age variable is being read in as a factor because of the
"".  If you were to replace it with NA, the type becomes numerical:

Before replacement:

str(Elder1)
'data.frame':   5 obs. of  2 variables:
 $ ID : Factor w/ 5 levels "ID1","ID2","ID3",..: 1 2 3 4 5
 $ age: Factor w/ 3 levels "","35","38": 3 2 1 NA NA

Notice that the "" is treated as a factor level.

After:

str(Elder1)
'data.frame':   5 obs. of  2 variables:
 $ ID : Factor w/ 5 levels "ID1","ID2","ID3",..: 1 2 3 4 5
 $ age: num  38 35 NA NA NA

SO, the question, is what do you want to do with that column?  An "NA"
value tells you honestly that the information is missing.  Replacing it
with a zero can be misleading and can bias some basic parameter
estimates.

After you know how you want to treat the data in that field, you may
have a better idea of how to handle the missing data.

JWD

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: how to replace <NA> values

kingsly
First of all I thank all the friends.

Though I  have written zero to replace NA in  previous email, I will replace with extreme value (99999).


On Tuesday, 21 January 2014 7:05 AM, jwd [via R] <[hidden email]> wrote:
On Sun, 19 Jan 2014 11:39:43 -0800 (PST)

kingsly <[hidden email]> wrote:

> Dear R community
>  
> I have a large data set contain some empty cells. Because of that,
> may be I am wrong, <NA> values are produced. Now I want replace both
> empty and <NA> values with zero.
> Elder1 <- data.frame(
>   ID=c("ID1","ID2","ID3","ID6","ID8"),
>   age=c(38,35,"",NA,NA))
> Output I am expecting
>  
> ID   age
> ID1  38
> ID2  35
> ID3  0
> ID6  0
> ID8  0
>  
> In advance I thank your help.

>
The age variable is being read in as a factor because of the
"".  If you were to replace it with NA, the type becomes numerical:

Before replacement:

str(Elder1)
'data.frame':   5 obs. of  2 variables:
 $ ID : Factor w/ 5 levels "ID1","ID2","ID3",..: 1 2 3 4 5
 $ age: Factor w/ 3 levels "","35","38": 3 2 1 NA NA

Notice that the "" is treated as a factor level.

After:

str(Elder1)
'data.frame':   5 obs. of  2 variables:
 $ ID : Factor w/ 5 levels "ID1","ID2","ID3",..: 1 2 3 4 5
 $ age: num  38 35 NA NA NA

SO, the question, is what do you want to do with that column?  An "NA"
value tells you honestly that the information is missing.  Replacing it
with a zero can be misleading and can bias some basic parameter
estimates.

After you know how you want to treat the data in that field, you may
have a better idea of how to handle the missing data.

JWD

______________________________________________
[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/how-to-replace-NA-values-tp4683831p4683894.html
To start a new topic under R help, email [hidden email]
To unsubscribe from R help, click here.
NAML


Reply | Threaded
Open this post in threaded view
|

Re: how to replace <NA> values

PIKAL Petr
Hi

> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of kingsly
> Sent: Tuesday, January 21, 2014 7:22 AM
> To: [hidden email]
> Subject: Re: [R] how to replace <NA> values
>
> First of all I thank all the friends.
>
> Though I  have written zero to replace NA in  previous email, I will
> replace with extreme value (99999).

Why? Many R functions has ability to work smoothly with NA values but AFAIK none is able to work with 99999 values.

It is the same as if you wanted to change bicycle tyres to wooden rim. You could ride but not with the same comfort.

Regards
Petr


>
>
>
> On Tuesday, 21 January 2014 7:05 AM, jwd [via R] <ml-
> [hidden email]> wrote:
>
> On Sun, 19 Jan 2014 11:39:43 -0800 (PST)
>
> kingsly <[hidden email]> wrote:
>
>
> ________________________________
> The age variable is being read in as a factor because of the "".  If
> you were to replace it with NA, the type becomes numerical:
>
> Before replacement:
>
> str(Elder1)
> 'data.frame':   5 obs. of  2 variables:
>  $ ID : Factor w/ 5 levels "ID1","ID2","ID3",..: 1 2 3 4 5
>  $ age: Factor w/ 3 levels "","35","38": 3 2 1 NA NA
>
> Notice that the "" is treated as a factor level.
>
> After:
>
> str(Elder1)
> 'data.frame':   5 obs. of  2 variables:
>  $ ID : Factor w/ 5 levels "ID1","ID2","ID3",..: 1 2 3 4 5
>  $ age: num  38 35 NA NA NA
>
> SO, the question, is what do you want to do with that column?  An "NA"
> value tells you honestly that the information is missing.  Replacing it
> with a zero can be misleading and can bias some basic parameter
> estimates.
>
> After you know how you want to treat the data in that field, you may
> have a better idea of how to handle the missing data.
>
> JWD
>
> ______________________________________________
> [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/how-to-replace-NA-
> values-tp4683831p4683894.html
> To start a new topic under R help, email ml-
> [hidden email]
> To unsubscribe from R help, click here.
> NAML
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-
> replace-NA-values-tp4683831p4683896.html
> Sent from the R help mailing list archive at Nabble.com.
>       [[alternative HTML version deleted]]


________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: how to replace <NA> values

John Kane
In reply to this post by kingsly
I'm pretty sure that what you have is not what you think you have.

Do a str(Elder1) on the data set and you will see that age is a factor not a numerical variable. Bascally you have a mangled data set from the look of it.

Why would you want to change NA's to 0's?  

John Kane
Kingston ON Canada


> -----Original Message-----
> From: [hidden email]
> Sent: Sun, 19 Jan 2014 11:39:43 -0800 (PST)
> To: [hidden email]
> Subject: [R] how to replace <NA> values
>
> Dear R community
> B
> I have a large data set contain some empty cells. BecauseB of that,B  may
> be I am wrong, <NA> values are produced.
> Now I want replace both empty and <NA> values with zero.
> B
> Elder1 <- data.frame(
> B  ID=c("ID1","ID2","ID3","ID6","ID8"),
> B  age=c(38,35,"",NA,NA))
> Output I am expecting
> B
> IDB B  age
> ID1B  38
> ID2B  35
> ID3B  0
> ID6B  0
> ID8B  0
> B
> In advance I thank your help.
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/how-to-replace-NA-values-tp4683831.html
> Sent from the R help mailing list archive at Nabble.com.
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [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.

____________________________________________________________
Send your photos by email in seconds...
TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if3
Works in all emails, instant messengers, blogs, forums and social networks.

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: Setting up an R server.

Aldi Kraja-2
In reply to this post by Michael Weylandt
Hi John,

A server it means a computer that has an operating system, where you can
run R. For example, a Linux OS can be run in a computer connected to
your Local Area Network at home. There you can install R and you can
communicate with it via batch mode or interactive. The simplest is you
become root of your system and use a software yum to install R (yum
install R). As Linux OS I use Fedora (free software), but one can use a
number of other flavors of Linux OS. This software (yum) will place the
executable of R in one of the bin dirs which is reachable from any
directory you enter in the system. What you need after it is an ssh
(secure shell) from the apps of ipad (apple), or if windows (x-win
software). At home, as long as you have connected your server with your
router, you can reach the server with no problem, by learning local
addresses or defining a name to the system, while remotely (distant from
your home) you need to know a fixed system address (probably you need to
buy it) from your internet company. If more than one server you can do R
parallel computing at home by using software such as gridware to
distribute jobs.

Hope this gives an idea about what you are planning to do :-) .

Best,

Aldi



On 1/20/2014 10:53 AM, R. Michael Weylandt wrote:

> Perhaps http://www.rstudio.com/ide/docs/server/getting_started
>
> Michael
>
> On Mon, Jan 20, 2014 at 9:12 AM, John Sorkin
> <[hidden email]> wrote:
>> Can someone provide suggestions about how to best set up an R server? I would like to be able to run R on my IPad. It sounds like the only way to do this is to have the IPad access an R server. The server will be at my home, connected to the internet via my cable company (comcast). I don't yet know if the server will be a linux box or a windows box. I would appreciate advice about setting up both kinds of servers.
>> Thank you,
>> John
>>
>> John David Sorkin M.D., Ph.D.
>> Professor of Medicine
>> Chief, Biostatistics and Informatics
>> University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
>> Baltimore VA Medical Center
>> 10 North Greene Street
>> GRECC (BT/18/GR)
>> Baltimore, MD 21201-1524
>> (Phone) 410-605-7119
>> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>>
>> Confidentiality Statement:
>> This email message, including any attachments, is for ...{{dropped:14}}
> ______________________________________________
> [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.

--

______________________________________________
[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.