[R] converting numeric to character and using character pattern

arun smartpink111 at yahoo.com
Mon Jul 15 20:50:18 CEST 2013


#or
pat1<-paste("http://www.", siter[,1], "......rdb", sep="", collapse = "|") 
 identical(pat,pat1)
#[1] TRUE
A.K.



----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: Irucka Embry <iruckaE at mail2world.com>
Cc: R help <r-help at r-project.org>
Sent: Monday, July 15, 2013 2:47 PM
Subject: Re: converting numeric to character and using character pattern

HI Irucka,
May be this is what you wanted: pat<-paste(paste0("http://www.",siter[,1],"......rdb"),collapse="|")
 pat
[1] "http://www.02437100......rdb|http://www.02439500......rdb|http://www.02441500......rdb|http://www.02446500......rdb|http://www.02467000......rdb|

----------------------------------------------------------------------------------------
A.K.



Hi, I am having a problem with my data set and conversion from numeric to character. 

Below is my code with comments on the specific problem below: 

hydraulicsites <- read.table("hydraulic_geometry_sites.csv", 
header = TRUE, sep = "\t", as.is = TRUE, stringsAsFactors = FALSE, 
colClasses = c("character",NA)) 
siter <- hydraulicsites[1] 

dput(siter) 
structure(list(site_no = c("02437100", "02439500", "02441500", 
"02446500", "02467000", "02470050", "03217500", "03219500", "03220510", 
"03227500", "03230700", "03231500", "03455000", "03497000", "03439000", 
"03439500", "03440000", "03441000", "03454500", "03479000", "03513500", 
"04177500", "04183500", "04185000", "04185500", "04186500", "04187500", 
"04188000", "04189000", "04189500", "04190000", "04191500", "04192500", 
"04193500", "06191500", "06214500", "06218500", "06222000", "06225500", 
"06228000", "06235500", "06259500", "06262000", "06264000", "06266000", 
"06269500", "06273000", "06276500", "06277500", "06279500", "06287000", 
"06288500", "06288500", "06289000", "06290500", "06293500", "06294700", 
"06329500", "06310000", "06309500", "06312500", "06311000", "06311500", 
"06313000", "06313500", "06315500", "06314000", "06315000", "06316500", 
"06317000", "06317500", "06318500", "06319500", "06320000", "06320500", 
"06323000", "06323500", "06324000", "06325500", "06324500", "06326500", 
"06426500", "06428000", "06428500", "06436000", "06437000", "06438000", 
"06821500", "06830000", "06850500", "06856600", "06860000", "06862500", 
"06864000", "06864500", "06865500", "06866000", "06877600", "06879500", 
"06887500", "06889000", "06891000", "06892500", "06342500", "06440000", 
"06818000", "06893000", "06934500", "05587500", "07010000", "07032000", 
"07289000")), .Names = "site_no", class = "data.frame", row.names = c(NA, 
-112L)) 

pat <- paste("http://www.", siter, "......rdb", sep="", collapse = "|") 
str(pat) 
 chr "www.c(\"02437100\", \"02439500\", \"02441500\", \"02446500\", \"02467000\""| __truncated__ 


OK, the problem is with pat. I need for pat to be the same 
as patter. I have a list of sites in .csv files that I need to process 
so I would like a more efficient way of doing the process than is shown 
below. 

Is there a way to get the results in pat to resemble those in patter? 

sites3 <- c("07103990", "402114105350101", "05056215") 
patter <- paste("www.", sites3, "......rdb", sep="", collapse = "|") 
dput(patter) 
"www.07103990......rdb|www.402114105350101......rdb|www.05056215......rdb" 


Thank you. 

Irucka Embry



More information about the R-help mailing list