Re: [R] Replace NA's with value in the next row

2013-11-14 Thread Jim Lemon

On 11/14/2013 04:02 PM, dila radi wrote:

Hi all,

I have a data set which treat missing value as NA and now I need to replace
all these NA's by using number in the same row but different column.

Here is the part of my data:
  V1 V2 V3 V4 V5 V6 V7  0 0 0 1.2 0 0 0.259  0 0 12.8 0 23.7 0 8.495  6 0
81.7 0.2 0 20 19.937  0 1.5 60.9 0 0 15.5 13.900  1 13 56.8 17.5 32.8 6.4
27.654  4 3 66.4 2 0.3 NA 17.145


I want to replace (V6, 6) with (V7, 6). I have about 1000 NA's in V6 which
I want to replace  with the same row in V7. The other values in V6, I want
to keep remain the same.

How to achieve this? Assuming my data is called Targetstation,  I have
tried this:

Targetstation- within(Targetstation, v6- replace(v6, is.na(v6), v7[is.na
(v6)]))

But R gives me this:

Warning messages:

1: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'

2: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'



Hi Dila,
You could do this like this:

V6NA-is.na(Targetstation$V6)
Targetstation$V6[V6NA]-Targetstation$V7[V6NA]

but if you want to use the above, I think you will have to replace the 
is.na(V6) with is.na(Targetstation$V6) or use the method above.


Jim

__
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] Replace NA's with value in the next row

2013-11-14 Thread Frans Marcelissen
R purists forbid the use of the for loop, but I am afraid this is the most
simple solution:

for (i in 1:(length(V6)-1)) if(is.na(V6[i])) V6[i]-V6[i+1]




2013/11/14 Jim Lemon j...@bitwrit.com.au

 On 11/14/2013 04:02 PM, dila radi wrote:

 Hi all,

 I have a data set which treat missing value as NA and now I need to
 replace
 all these NA's by using number in the same row but different column.

 Here is the part of my data:
   V1 V2 V3 V4 V5 V6 V7  0 0 0 1.2 0 0 0.259  0 0 12.8 0 23.7 0 8.495  6 0
 81.7 0.2 0 20 19.937  0 1.5 60.9 0 0 15.5 13.900  1 13 56.8 17.5 32.8 6.4
 27.654  4 3 66.4 2 0.3 NA 17.145


 I want to replace (V6, 6) with (V7, 6). I have about 1000 NA's in V6 which
 I want to replace  with the same row in V7. The other values in V6, I want
 to keep remain the same.

 How to achieve this? Assuming my data is called Targetstation,  I have
 tried this:

 Targetstation- within(Targetstation, v6- replace(v6, is.na(v6), v7[
 is.na
 (v6)]))

 But R gives me this:

 Warning messages:

 1: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'

 2: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'


  Hi Dila,
 You could do this like this:

 V6NA-is.na(Targetstation$V6)
 Targetstation$V6[V6NA]-Targetstation$V7[V6NA]

 but if you want to use the above, I think you will have to replace the
 is.na(V6) with is.na(Targetstation$V6) or use the method above.

 Jim


 __
 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.




-- 


---
dr F.H.G. (Frans) Marcelissen
DigiPsy (www.DigiPsy.nl http://www.digipsy.nl/)
Pomperschans 26
5595 AV Leende
tel: 040 2065030/06 2325 06 53
skype adres: frans.marcelissen
email: frans.marcelis...@digipsy.nl

[[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] Replace NA's with value in the next row

2013-11-14 Thread Bert Gunter
On Thu, Nov 14, 2013 at 1:13 AM, Frans Marcelissen
frans.marcelis...@digipsy.nl wrote:
 R purists forbid the use of the for loop,

That is utter nonsense. Please do not make such statements when you
have no idea what you're talking about. It just promulgates confusion.

-- Bert

 simple solution:

 for (i in 1:(length(V6)-1)) if(is.na(V6[i])) V6[i]-V6[i+1]




 2013/11/14 Jim Lemon j...@bitwrit.com.au

 On 11/14/2013 04:02 PM, dila radi wrote:

 Hi all,

 I have a data set which treat missing value as NA and now I need to
 replace
 all these NA's by using number in the same row but different column.

 Here is the part of my data:
   V1 V2 V3 V4 V5 V6 V7  0 0 0 1.2 0 0 0.259  0 0 12.8 0 23.7 0 8.495  6 0
 81.7 0.2 0 20 19.937  0 1.5 60.9 0 0 15.5 13.900  1 13 56.8 17.5 32.8 6.4
 27.654  4 3 66.4 2 0.3 NA 17.145


 I want to replace (V6, 6) with (V7, 6). I have about 1000 NA's in V6 which
 I want to replace  with the same row in V7. The other values in V6, I want
 to keep remain the same.

 How to achieve this? Assuming my data is called Targetstation,  I have
 tried this:

 Targetstation- within(Targetstation, v6- replace(v6, is.na(v6), v7[
 is.na
 (v6)]))

 But R gives me this:

 Warning messages:

 1: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'

 2: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'


  Hi Dila,
 You could do this like this:

 V6NA-is.na(Targetstation$V6)
 Targetstation$V6[V6NA]-Targetstation$V7[V6NA]

 but if you want to use the above, I think you will have to replace the
 is.na(V6) with is.na(Targetstation$V6) or use the method above.

 Jim


 __
 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.




 --


 ---
 dr F.H.G. (Frans) Marcelissen
 DigiPsy (www.DigiPsy.nl http://www.digipsy.nl/)
 Pomperschans 26
 5595 AV Leende
 tel: 040 2065030/06 2325 06 53
 skype adres: frans.marcelissen
 email: frans.marcelis...@digipsy.nl

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

(650) 467-7374

__
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] Replace NA's with value in the next row

2013-11-14 Thread arun


Hi,

I think you used a column that doesn't exist in the dataset.

Targetstation - read.table(text=V1 V2 V3 V4 V5 V6 V7  
0 0 0 1.2 0 0 0.259
0 0 12.8 0 23.7 0 8.495
 6 0 81.7 0.2 0 20 19.937
 0 1.5 60.9 0 0 15.5 13.900
 1 13 56.8 17.5 32.8 6.4 27.654
  4 3 66.4 2 0.3 NA 17.145,sep=,header=TRUE)


within(Targetstation, V6 - replace(V6,is.na(V6),V7[is.na(V6)]))
  V1   V2   V3   V4   V5 V6 V7
1  0  0.0  0.0  1.2  0.0  0.000  0.259
2  0  0.0 12.8  0.0 23.7  0.000  8.495
3  6  0.0 81.7  0.2  0.0 20.000 19.937
4  0  1.5 60.9  0.0  0.0 15.500 13.900
5  1 13.0 56.8 17.5 32.8  6.400 27.654
6  4  3.0 66.4  2.0  0.3 17.145 17.145

#if you use:
 !is.na(Targetstation$v6) #'v6' and 'V6' are different
logical(0)
Warning message:
In is.na(Targetstation$v6) :
  is.na() applied to non-(list or vector) of type 'NULL'



A.K.









On Thursday, November 14, 2013 2:26 AM, dila radi dilarad...@gmail.com wrote:
Hi all,

I have a data set which treat missing value as NA and now I need to replace
all these NA's by using number in the same row but different column.

Here is the part of my data:
V1 V2 V3 V4 V5 V6 V7  0 0 0 1.2 0 0 0.259  0 0 12.8 0 23.7 0 8.495  6 0
81.7 0.2 0 20 19.937  0 1.5 60.9 0 0 15.5 13.900  1 13 56.8 17.5 32.8 6.4
27.654  4 3 66.4 2 0.3 NA 17.145


I want to replace (V6, 6) with (V7, 6). I have about 1000 NA's in V6 which
I want to replace  with the same row in V7. The other values in V6, I want
to keep remain the same.

How to achieve this? Assuming my data is called Targetstation,  I have
tried this:

Targetstation - within(Targetstation, v6 - replace(v6, is.na(v6), v7[is.na
(v6)]))

But R gives me this:

Warning messages:

1: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'

2: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'


How to solve this?

Thank you in advance.

Regards,

Dila.

    [[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] Replace NA's with value in the next row

2013-11-13 Thread dila radi
Hi all,

I have a data set which treat missing value as NA and now I need to replace
all these NA's by using number in the same row but different column.

Here is the part of my data:
 V1 V2 V3 V4 V5 V6 V7  0 0 0 1.2 0 0 0.259  0 0 12.8 0 23.7 0 8.495  6 0
81.7 0.2 0 20 19.937  0 1.5 60.9 0 0 15.5 13.900  1 13 56.8 17.5 32.8 6.4
27.654  4 3 66.4 2 0.3 NA 17.145


I want to replace (V6, 6) with (V7, 6). I have about 1000 NA's in V6 which
I want to replace  with the same row in V7. The other values in V6, I want
to keep remain the same.

How to achieve this? Assuming my data is called Targetstation,  I have
tried this:

Targetstation - within(Targetstation, v6 - replace(v6, is.na(v6), v7[is.na
(v6)]))

But R gives me this:

Warning messages:

1: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'

2: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'


How to solve this?

Thank you in advance.

Regards,

Dila.

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