R error in unique.default(x) unique() applies only to vectors
This is a very common mistake, you need to use the named argument FUN
:
ave(state$inc, state$region, FUN = mean)
otherwise mean
will be interpreted as another grouping variable (part of the ...
argument to ave
.)
Error in unique.default(x) : unique() applies only to vectors
We could use dplyr
library(dplyr)
DF %>%
count(month, day)
R Plotly Error in unique.default(x): unique() applies only to vectors
Removing the color = ~am
argument from your call to the plot_ly
function seems to produce the required plot. Code and resulting plot below.
library(plotly)
plot1 <- structure(list(Power = c(69.9874083088991, 52.8823845511674,
57.466598971878, 54.7682734834554, 61.8007644271192, 67.2033748459662,
55.8696111041597, 64.5915381203366, 63.6683866870196, 77.9284830962032,
47.9240347517641, 70.6545718514277, 63.624972518279, 69.0612933117757,
56.7737161200819), gas = c(1.1788726505072, 1.49143516242048,
1.21339029609897, 1.18616542299913, 1.85313915518133, 1.19986033487848,
1.33798310271697, 1.42071527189892, 1.96603005333785, 1.88860512508931,
1.67180843784324, 1.35418148197551, 1.6656400541228, 1.14499850347505,
1.27237787462861), margin = c(188.114554495799, 160.424593244341,
167.169831096674, 166.203918308567, 170.724537947621, 175.021242542284,
161.591428698362, 166.072058276843, 175.075797678045, 190.707360569274,
142.569752983863, 174.685436684351, 170.63549056998, 184.975371979721,
161.664095244404)), class = "data.frame", row.names = c(NA, -15L
))
plot_ly(plot1, x = ~Power, y = ~gas, z = ~margin,
marker = list(color = ~margin,
colorscale = list(c(0, "rgb(227, 25, 54)"), list(1, "rgb(194, 205, 35)")),
showscale = F)) %>%
add_markers() %>%
layout(
title = "Test",
scene = list(xaxis = list(title = 'Electricity ($/MWh)'),
yaxis = list(title = 'Gas ($/GJ)'),
zaxis = list(title = 'Commodity Margin ($ million)'))
)
Error in unique.default(x) : unique() applies only to vectors in rLiDAR package
The ID vector must be named "id"
This is somewhat documented in the help page of chullLiDAR2D
:
Arguments
xyid
A 3-column matrix with the x, y coordinates and points id of the LiDAR point cloud.
Looking at the function itself, the "id" is hard-coded.
# chullLiDAR2D #
function (xyid)
{
spdfList <- plyr::dlply(as.data.frame(xyid), "id",
function(input) { ...
So, just change the name from ID
to id
and all will be well.
#Setting the IDs of the points
id <- as.factor(clLAS$cluster)
#Setting the XYZID input
XY_ID <- cbind(XYZ[,1:2], id)
#Calculating the LiDAR convex hull of the clusters
chull_Trees <- chullLiDAR2D(XY_ID)
# Plotting the LiDAR convex hull
library(sp)
plot(SpatialPoints(xyid[,1:2]),cex=0.5,col=xyid[,3])
plot(chullTrees$chullPolygon, add=TRUE, border='black')
Error in unique.default(x, nmax = nmax) : unique() applies only to vectors in R
Here 'ave' doesn't have any of the "Grouping variables, typically factors, all of the same length as x." as described in ?ave (the ... args).
If the goal is to replace NA's with the mean of bmi, maybe just straight up mean is what you want?
hm_rows=10;
ds=data.frame(bmi=runif(hm_rows,0,10))
ds[c(1,2,4,6),"bmi"] <- NA
{ds$bmi=ifelse(is.na(ds$bmi), mean(ds$bmi,na.rm=TRUE),ds$bmi)}
SparkR : Error in unique.default(x, nmax = nmax) :unique() applies only to vectors
There are two problems with your code: firstly factor is not a SparkR type, you're restricted to strings, secondly as.type does not work on DataFrame columns, you should use the following conversion code
babies$bwt2 <- cast(babies$bwt2,'string')
Related Topics
Multiple Boxplots Using Ggplot
Installing R 3.5.0 with --Enable-R-Shlib
How to Do Conditional Grouping of Data in R
R: How to Draw a Line with Multiple Arrows in It
Replacing All Missing Values in R Data.Table with a Value
How to Automatically Include All 2-Way Interactions in a Glm Model in R
Efficient Alternatives to Merge for Larger Data.Frames R
How to Remove Rows That Have Only 1 Combination for a Given Id
Given a Set of Random Numbers Drawn from a Continuous Univariate Distribution, Find the Distribution
Importing Data into R from Google Spreadsheet
What Are 'User' and 'System' Times Measuring in R System.Time(Exp) Output
R How to Convert a Numeric into Factor with Predefined Labels
Create Unique Identifier from the Interchangeable Combination of Two Variables
Fitting Linear Model/Anova by Group