Skip to content
Prev 206908 / 398503 Next

Data Manipulation

Peter Rote wrote:
If this happens, try to do a 

finvizAllexETF$Ticker[AllexETF$Industry == ind2[i]] 

You will note that it returns not one, but many items, and assigning it to
ind[i] will fail. Sometimes, it helps to add a [1] at the end, but there is
another problem that these are factors and you want strings.

The example below shows on method:

set.seed(4711)
AlexETF = 
 data.frame(Industry=sample(c("Business Services", "Aluminium","Regional
Airlines"),10,TRUE),Price = rnorm(10,10))
by(AlexETF,AlexETF$Industry,function(a) {
     filename = paste(gsub(" ","",a$Industry[1]),".txt",sep="")
     print(filename)
     write.table(a,file=filename)
   }
)

 
Dieter