0
votes

Trying to solve an issue with an R Code my employer has provided me. I'm not particularly experienced with R so I apologize if this is something simple. I tried searching for it but the other responses seems very specific to their problem, so they didn't help.

I am getting this error when attempting to export my data to Excel.

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ""powerCurve"" to a data.frame

I am running this block of code from a larger equation.

##Checking # replications RepMax=aggregate(Rep~Trial, max, data=Power_Select1) mean(RepMax$Rep)

##verifying fixed effect fixef(Model_ISA_Power)

##assigning newfix effect---Yield Differences 1, 2, 3, 4, 5, 6 bu/acre fixef(Model_ISA_Power)["TRTManure+50"]=1.0

modelTrial = extend(Model_ISA_Power, along="Rep", n=20)

##Replications

\Reps_Bushel_1 <- powerCurve(modelTrial, along="Rep", alpha=.05, nsim=100, > breaks=3:15) print(Reps_Bushel_1)

xlsx.writeMultipleData("OutputTest.xlsx", Reps_Bushel_1)

Is there anyone out there that can help me identify how to get this information into Excel, or at least why I receive the Coercion error?

When I run the script, I get data formatted like this:

> print(Reps_Bushel_1)
Power for predictor 'TRT', (95% confidence interval),
by largest value of Rep:
      3: 12.00% ( 6.36, 20.02) - 18 rows
      4: 11.00% ( 5.62, 18.83) - 22 rows
      5: 10.00% ( 4.90, 17.62) - 28 rows
      6: 10.00% ( 4.90, 17.62) - 34 rows
      7:  7.00% ( 2.86, 13.89) - 40 rows
      8:  8.00% ( 3.52, 15.16) - 44 rows
      9:  5.00% ( 1.64, 11.28) - 50 rows
     10:  7.00% ( 2.86, 13.89) - 56 rows
     11:  9.00% ( 4.20, 16.40) - 62 rows
     12:  8.00% ( 3.52, 15.16) - 66 rows
     13: 10.00% ( 4.90, 17.62) - 72 rows
     14: 10.00% ( 4.90, 17.62) - 78 rows
     15: 10.00% ( 4.90, 17.62) - 84 rows

We are trying to get the information from 3: to the end to export to Excel.

1
Please read the documentation of the function powerCurve(), section Value - jogo

1 Answers

2
votes

It looks like objects of class PowerCurve are not stored as data frames.

The first thing you should do is to look at the structure of your object:

str(Reps_Bushel_1) 

I suspect this object has several components, each with different names, as seen via the command:

names(Reps_Bushel_1) 

Let's say the components are named component1, component2, etc. Then you can extract the component you are interested in - say, component1 - and check its structure:

str(Reps_Bushel_1$component1)

If the structure is a "data.frame" or even "matrix", you would be able to export Reps_Bushel_1$component1 out of R without any problems. If it is not, then we'd need more details to be able to help.