Re: [R] substring if a record has a "\"

2014-05-02 Thread arun
Hi,
Try:
dat <- structure(list(`1` = c("Marius Muller -\nIT Services", 
"Rockwood\nBrockhues", 
"Microlog Services\nMarcos", "Firefox Services")), .Names = "1", class = 
"data.frame", row.names = c("A", 
"B", "C", "D"))

dat$`1` <- gsub("\n.*","",dat$`1`)
dat
#  1
#A   Marius Muller -
#B  Rockwood
#C Microlog Services
#D  Firefox Services


A.K.


On Friday, May 2, 2014 3:19 AM, Mat  wrote:
Hello togehter, 

i have a litte problem. I have a data.frame with a view entries like this
one:
      1
A   Marius Muller -\nIT Services
B   Rockwood\nBrockhues
C   Microlog Services\nMarcos
D   Firefox Services

I now want only the first description in the column until the "\n". How can
i do this?

The solution look like this one:

      1
A   Marius Muller -
B   Rockwood
C   Microlog Services
D   Firefox Services

Thank you.

Best regards. Mat.



--
View this message in context: 
http://r.789695.n4.nabble.com/substring-if-a-record-has-a-tp4689857.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] substring if a record has a "\"

2014-05-02 Thread Mat
works perfect, thank you :-)



--
View this message in context: 
http://r.789695.n4.nabble.com/substring-if-a-record-has-a-n-tp4689857p4689860.html
Sent from the R help mailing list archive at Nabble.com.

__
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] substring if a record has a "\"

2014-05-02 Thread Pascal Oettli
Hello,

Something like that?

x <- c('Marius Muller -\nIT Services','Rockwood\nBrockhues','Microlog
Services\nMarcos','Firefox Services')
x <- sapply(strsplit(x, '\n'), '[', 1)
x
[1] "Marius Muller -"   "Rockwood"  "Microlog Services"
[4] "Firefox Services"

Regards,
Pascal

On Fri, May 2, 2014 at 4:17 PM, Mat  wrote:
> Hello togehter,
>
> i have a litte problem. I have a data.frame with a view entries like this
> one:
>   1
> A   Marius Muller -\nIT Services
> B   Rockwood\nBrockhues
> C   Microlog Services\nMarcos
> D   Firefox Services
>
> I now want only the first description in the column until the "\n". How can
> i do this?
>
> The solution look like this one:
>
>   1
> A   Marius Muller -
> B   Rockwood
> C   Microlog Services
> D   Firefox Services
>
> Thank you.
>
> Best regards. Mat.
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/substring-if-a-record-has-a-tp4689857.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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.



-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan

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