# paste command creates alphanumeric data. How can I then use it?

This code to normalize variable x1 runs:

`````` newdata <- subset(df3, abs(normalizeZ(x1)) >= 3)
cat("There are", nrow(newdata),"potential X1 outliers >= |3| in df3", "\n")
``````

Output:
There are 128 potential X1 outliers >= |3| in df3

When I use the paste command as a parameter for a dataset there is a switch made from numeric to alphanumeric somewhere in the following code. I have tried to correct for that.

``````> for(i in 1:11){
+ v <- paste("x",i,sep="")
+ temp <- as.numeric(df3[[v]])
+ temp2 <- normalizeZ(temp)
+ newdata <- subset(df3, abs(temp2) >= 3)
+ cat("There are", nrow(newdata),"potential", v,"outliers >= |3| in df3" ,"\n")
+ }

Output:
There are 0 potential x1 outliers >= |3| in df3
There are 0 potential x2 outliers >= |3| in df3
There are 0 potential x3 outliers >= |3| in df3
There are 0 potential x4 outliers >= |3| in df3
There are 0 potential x5 outliers >= |3| in df3
There are 0 potential x6 outliers >= |3| in df3
There are 0 potential x7 outliers >= |3| in df3
There are 0 potential x8 outliers >= |3| in df3
There are 0 potential x9 outliers >= |3| in df3
There are 0 potential x10 outliers >= |3| in df3
There are 0 potential x11 outliers >= |3| in df3

Another attempt:

> for(i in 1:11){
+ v <- paste("x",i,sep="")
+ newdata <- subset(df3, abs(normalizeZ(df3[[v]])) >= 3)
+ cat("There are", nrow(newdata),"potential", v,"outliers >= |3| in df3" ,"\n")
+ }

Warning: argument is not numeric or logical: returning NAThere are 0 potential x1 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x2 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x3 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x4 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x5 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x6 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x7 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x8 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x9 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x10 outliers >= |3| in df3
Warning: argument is not numeric or logical: returning NAThere are 0 potential x11 outliers >= |3| in df3
>``````

Yes, x1 .. x11. If 1:11 is sought, why go through paste in the first place? What am I missing about the statement of the problem?

it is x1,x2,...x11 that is needed not 1,2,3...11. I am using a loop. THis is a new error. It has been running.

I think problem is the name of the normalized variables z_z,x1_z,...x11_z in df3.
drop the _z's and keep z-transformed variables but renamed as z,x1,x2,...x11 in df3.

Without a a `reprex`. See the FAQ, I have to guess.

``````df3 <- mtcars[1:11]
df3[1,1] <- 10000
colnames(df3) <- paste0("x",1:11)
normalizeZ <- function(x) (x - min(x))/(max(x)-min(x))

for(i in 1:11){
v = paste0("x",i,sep="")
newdata = subset(df3, abs(normalizeZ(df3[[v]])) >= 1)
cat("There are", nrow(newdata),"potential", v,"outliers >= |1| in df3" ,"\n")
}
#> There are 1 potential x1 outliers >= |1| in df3
#> There are 14 potential x2 outliers >= |1| in df3
#> There are 1 potential x3 outliers >= |1| in df3
#> There are 1 potential x4 outliers >= |1| in df3
#> There are 1 potential x5 outliers >= |1| in df3
#> There are 1 potential x6 outliers >= |1| in df3
#> There are 1 potential x7 outliers >= |1| in df3
#> There are 14 potential x8 outliers >= |1| in df3
#> There are 13 potential x9 outliers >= |1| in df3
#> There are 5 potential x10 outliers >= |1| in df3
#> There are 1 potential x11 outliers >= |1| in df3
``````

Created on 2023-03-10 with reprex v2.0.2

1 Like