[R] How to extract from a column in a table?
arun
smartpink111 at yahoo.com
Thu Aug 16 22:03:40 CEST 2012
Hi,
Try this:
dat1<-readLines(textConnection("Name
Budlamp-Woodcutter Complex - 15 to 60% slope (60/25/15)
Budlamp-Woodcutter Complex - 15 to 60% slope (60/25/15)
Terrarossa-Blacktail-Pyeatt Complex - 1 to 40% slope (40/35/15/10)
Terrarossa-Blacktail-Pyeatt Complex - 1 to 40% slope (40/35/15/10)
"))
dat3<-data.frame(dat2[-1,])
colnames(dat3)<-"Name"
col2<-gsub(".*-\\s(.*slope).*","\\1",dat3$Name)
col3<-gsub(".*(\\(.*\\))","\\1",dat3$Name)
col1<-gsub("(.*Complex).*","\\1",dat3$Name)
dat3New<-data.frame(col1,col2,col3)
dat3New
col1 col2 col3
1 Budlamp-Woodcutter Complex 15 to 60% slope (60/25/15)
2 Budlamp-Woodcutter Complex 15 to 60% slope (60/25/15)
3 Terrarossa-Blacktail-Pyeatt Complex 1 to 40% slope (40/35/15/10)
4 Terrarossa-Blacktail-Pyeatt Complex 1 to 40% slope (40/35/15/10)
A.K.
----- Original Message -----
From: Sapana Lohani <lohani.sapana at ymail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Thursday, August 16, 2012 2:41 PM
Subject: [R] How to extract from a column in a table?
Hi,
I have a table in which one column has the name of the objects as shown below.
Name
Budlamp-Woodcutter Complex - 15 to 60% slope (60/25/15)
Budlamp-Woodcutter Complex - 15 to 60% slope (60/25/15)
Terrarossa-Blacktail-Pyeatt Complex - 1 to 40% slope (40/35/15/10)
Terrarossa-Blacktail-Pyeatt Complex - 1 to 40% slope (40/35/15/10)
How can I split the single column into three columns like name (Budlamp-Woodcutter Complex), slope (15 to 60% slope) and percentage (60/25/15)
thanks
[[alternative HTML version deleted]]
______________________________________________
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.
More information about the R-help
mailing list