Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:32:26+00:00 2026-06-17T09:32:26+00:00

I have a data frame is like this: dput(xx) structure(list(TimeStamp = structure(c(15705, 15706), class

  • 0

I have a data frame is like this:

dput(xx)

structure(list(TimeStamp = structure(c(15705, 15706), class = "Date"), 
    Host = c("Host1", "Host2"), OS = structure(c(1L, 1L), .Label = "solaris", class = "factor"), 
    ID = structure(c(1L, 1L), .Label = "1234", class = "factor"), 
    Class = structure(c(1L, 1L), .Label = "Processor", class = "factor"), 
    Stat = structure(c(1L, 1L), .Label = "CPU", class = "factor"), 
    Instance = structure(c(1L, 1L), .Label = c("_Total", "CPU0", 
    "CPU1", "CPU10", "CPU11", "CPU12", "CPU13", "CPU14", "CPU15", 
    "CPU16", "CPU17", "CPU18", "CPU19", "CPU2", "CPU20", "CPU21", 
    "CPU22", "CPU23", "CPU3", "CPU4", "CPU5", "CPU6", "CPU7", 
    "CPU8", "CPU9"), class = "factor"), Average = c(4.39009345794392, 
    5.3152972972973), Min = c(3.35, -0.01), Max = c(5.15, 72.31
    )), .Names = c("TimeStamp", "Host", "OS", "ID", "Class", 
"Stat", "Instance", "Average", "Min", "Max"), row.names = c(NA, 
-2L), class = "data.frame")

This data frame is huge and it has many Hosts. The challenge that I am having is that when a host like above does not have enough data points, the following ggplot fails, basically complaining about not having enough data points to draw the graph.

ggplot(xx, aes(TimeStamp, Max, group=Host, colour=Host)) + geom_point() + geom_smooth(mehtod="loess")

How can I check and see if a particular Host in this data frame has greater than 10 data points, if yes use method=”loess”.
if the number of data points for a Host is less than 10, use method=”lm”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:32:26+00:00Added an answer on June 17, 2026 at 9:32 am

    Yes, it was tricky to find, but it seems to be possible,

    # for reproducibility
    set.seed(42)
    # The idea is to first split the data to < 10 and >= 10 points
    # I use data.table for that
    require(data.table)
    dt <- data.frame(Host = rep(paste("Host", 1:10, sep=""), sample(1:20, 10)), 
             stringsAsFactors = FALSE)
    dt <- transform(dt, x=sample(1:nrow(dt)), y = 15*(1:nrow(dt)))
    dt <- data.table(dt, key="Host")
    dt1 <- dt[, .SD[.N >= 10], by = Host]
    dt2 <- dt[, .SD[.N < 10], by = Host]
    
    # on to plotting now    
    require(ggplot2)
    # Now, dt1 has all Hosts with >= 10 observations and dt2 the other way round
    # plot now for dt1
    p <- ggplot(data=dt1, aes(x = x, y = y, group = Host)) + geom_line() + 
             geom_smooth(method="loess", se=T)
    # plot geom_line for dt2 by telling the data and aes
    # The TRICKY part: add geom_smooth by telling data=dt2
    p <- p + geom_line(data = dt2, aes(x=x, y=y, group = Host)) + 
                geom_smooth(data = dt2, method="lm", se=T)
    
    p
    

    (This is an ugly example. But it gives you the idea).
    ggplot2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this data frame: dput(df2) structure(list(Receiver = structure(c(4L, 3L, 2L, 1L), .Label =
I have a data.frame like this: (t=structure(list(count = c(NA, 2, NA, NA, NA, 8,
I have a data frame like this: df Date Player Injured 1/2/2012 A No
I have a data frame like this: Server Date Server Space 1 2010-01-30 server1
I have a data frame called y dput(y) structure(list(val1 = c(25L, 615L, 30L, 76L,
I have a data frame that looks like this: site date var dil 1
I have a melted data.frame, dput(x), below: ## dput(x) x <- structure(list(variable = structure(c(1L,
I have a data frame like this: Date Impacting_APP Impacted_APP 1/1/2012 PS PayRoll 1/2/2012
I have a data frame like this Date Team Score 1/1/2010 A 10 1/1/2010
I have an R data frame that looks like this: z = as.data.frame(list(Col1=c(a,c,e,g),Col2=c(b,d,f,h),Col3=c(1,2,5,3,5,7,9,8,1))) >

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.