An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130326/e2d88154/attachment.pl>
Shifting cells and removing blanks
3 messages · ankur verma, Nordlund, Dan (DSHS/RDA), arun
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of ankur verma Sent: Tuesday, March 26, 2013 10:22 AM To: r-help at r-project.org Subject: [R] Shifting cells and removing blanks Hi , I've been struggling with this problem. Initially I thought something like a na.locf would help but I'm at a dead end. I have a data set like this: ID Prod1 Prod2 Prod3 Prod4 Prod5 01 A - B - C 02 - F - G - 03 H - - - J
What does "like this" mean? Is this a text file, or a list, or a dataframe, or a matrix, or ...? You say you want to remove all blanks. Are the hyphens your attempt to represent blanks in the email, or do they actually exist?
And I would like to remove all the blanks and get a aggregated list against each ID like so: 01 A B C 02 F G 03 H J
Again, do you want this output in a text file or some R structure? If an R structure, which one?
Can anyone suggest a function or a package on how to achieve this ?
Not until you provide a reproducible example as the posting guide asks. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
If the OP wanted a list output and if the data is what it looks like, may be this helps. dat1<-read.table(text=" ?ID? Prod1? Prod2? Prod3? Prod4? Prod5 01??? A???????????? -?????????? B??????? -?????????? C 02????? -?????????? F?????????? -?????????? G??????? - 03????? H???????? -???????????? -?????????? -???????? J ",sep="",header=TRUE,stringsAsFactors=FALSE) ?lapply(split(dat1[,-1],dat1$ID),function(x) x[x!="-"]) $`1` [1] "A" "B" "C" $`2` [1] "F" "G" $`3` [1] "H" "J" A.K. ----- Original Message ----- From: "Nordlund, Dan (DSHS/RDA)" <NordlDJ at dshs.wa.gov> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Tuesday, March 26, 2013 1:34 PM Subject: Re: [R] Shifting cells and removing blanks
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of ankur verma Sent: Tuesday, March 26, 2013 10:22 AM To: r-help at r-project.org Subject: [R] Shifting cells and removing blanks Hi , I've been struggling with this problem. Initially I thought something like a na.locf would help but I'm at a dead end. I have a data set like this: ? ID? Prod1? Prod2? Prod3? Prod4? Prod5 01? ? A? ? ? ? ? ? -? ? ? ? ? B? ? ? ? -? ? ? ? ? C 02? ? ? -? ? ? ? ? F? ? ? ? ? -? ? ? ? ? G? ? ? ? - 03? ? ? H? ? ? ? -? ? ? ? ? ? -? ? ? ? ? -? ? ? ? J
What does "like this" mean?? Is this a text file, or a list, or a dataframe, or a matrix, or ...?? You say you want to remove all blanks.? Are the hyphens your attempt to represent blanks in the email, or do they actually exist?
And I would like to remove all the blanks and get a aggregated list against each ID like so: 01 A B C 02 F G 03 H J
Again, do you want this output in a text file or some R structure?? If an R structure, which one?
Can anyone suggest a function or a package on how to achieve this ?
Not until you provide a reproducible example as the posting guide asks. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 ______________________________________________ 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.