0

I thought the summary function in R could take character variables given the file it points to is numeric. bbb is giving me good results but the summary of aaa is giving me problems.

# Descriptives For Machine.x
for (n in 1:3500){
   machine_name = paste("machine.wt$Machine.", n, sep="")
   aaa = summary (paste("machine.wt$Machine.", n, sep=""))
   bbb = summary (machine.wt$Machine.1)
}

Error in x - mx : non-numeric argument to binary operator
In addition: Warning messages:
1: In mean.default(x, na.rm = na.rm) :
  argument is not numeric or logical: returning NA
2: In var(x, na.rm = na.rm) : NAs introduced by coercion
3: In mean.default(x, na.rm = na.rm, trim = trim) :
  argument is not numeric or logical: returning NA
4: In var(x, na.rm = na.rm) : NAs introduced by coercion
5: In mean.default(x) : argument is not numeric or logical: returning NA

My data is very simple:

Obs.1   Machine.1   Obs.1   Machine.2   Obs.2   Machine.3   Obs.3   Machine.4
1   302.3   1   302.8   1   315.1   1   300.9
2   295.3   2   314.3   2   306.7   2   317.5
3   301.4   3   308.4   3   309.0   3   304.3
4   318.2   4   295.2   4   321.3   4   293.2
5   320.4   5   313.5   5   326.4   5   308.0

2 Answers 2

1

How about using subset and grepl to avoid the loop altogether?

summary(subset(machine.wt,select=grepl("^Machine",names(machine.wt))))
Sign up to request clarification or add additional context in comments.

1 Comment

I like both of these answers but I think I have to go with this one, cuz it bent my brain.
0

See fortune(312) then try

summary( machine.wt[[ paste0('Machine.',n) ]] )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.