Re: [R] trim NA from concatenate result

2021-06-02 Thread Kai Yang via R-help
Hi Rui, I use the code to fix my problem: try$newcol <- gsub(" NA", "", try$newcol) But, I'll try your solution later. Thank you for your help. Kai On Wednesday, June 2, 2021, 02:08:18 PM PDT, Kai Yang via R-help wrote: Hi List, I use paste function to concatenate  3 character columns tog

Re: [R] trim NA from concatenate result

2021-06-02 Thread Rui Barradas
Hello, Something like this? df1 <- read.table(text = " NA NA NA NA NA Adenocarcinoma NA Other NA") df1 apply(df1, 1, function(x){ if(all(is.na(x))){ NA_character_ }else{ paste(x[!is.na(x)], collapse = "") } }) And please configure your e-mail client not to post in HTML format.

[R] trim NA from concatenate result

2021-06-02 Thread Kai Yang via R-help
Hi List, I use paste function to concatenate  3 character columns together. when I run table to see that, I found 3 categories. How can I write script to trim NA in 2nd and 3rd group and set the first one as NA? Thanks, Kai NA NA NA  NA NA Adenocarcinoma NA Other NA [[alternative HTML ver