Dear All,
I am bit stuck to a problem of replacing to NA.
I have big data set but here is the toy example:-
test-data.frame(
test1=c(,Hi,Hello),
test2=c(Hi,,Bye),
test3=c(Hello,,))
If the data as in above, I could change all to NA by this code:-
for(i in 1:3){
for(j in 1:3){
if(test[j,i]==){
On Jan 6, 2014, at 5:57 AM, vikram ranga babuaw...@gmail.com wrote:
Dear All,
I am bit stuck to a problem of replacing to NA.
I have big data set but here is the toy example:-
test-data.frame(
test1=c(,Hi,Hello),
test2=c(Hi,,Bye),
test3=c(Hello,,))
If the data as in above, I could
try this:
test-data.frame(
+ test1=c(,Hi,Hello),
+ test2=c(Hi,NA,Bye),
+ test3=c(Hello,,))
test
test1 test2 test3
1 Hi Hello
2Hi NA
3 Hello Bye
test[] - lapply(test, function(x){
+ x[!is.na(x) x == ''] - NA
+ x
+ })
test
test1 test2 test3
1 NAHi Hello
2
Hi,
Try:
test[test== !is.na(test)] - NA
A.K.
On Monday, January 6, 2014 7:51 AM, vikram ranga babuaw...@gmail.com wrote:
Dear All,
I am bit stuck to a problem of replacing to NA.
I have big data set but here is the toy example:-
test-data.frame(
test1=c(,Hi,Hello),
test2=c(Hi,,Bye),
Hi Arun Jim Marc,
Thank you!
The solution worked well!
It seems I am using too many unnecessary loops to solve my problems. I
have tried using is.na() before posting:
for(i in 1:3){
for(j in 1:3){
if(is.na(test[j,i])){
test[j,i]=
}
}
} # but here the factors were creating problems.
Thanks
5 matches
Mail list logo