How to use S_ISREG() and S_ISDIR() POSIX Macros?

You’re using S_ISREG() and S_ISDIR() correctly, you’re just using them on the wrong thing. In your while((dit = readdir(dip)) != NULL) loop in main, you’re calling stat on currentPath over and over again without changing currentPath: if(stat(currentPath, &statbuf) == -1) { perror(“stat”); return errno; } Shouldn’t you be appending a slash and dit->d_name to currentPath … Read more

Method to extract stat_smooth line fit

Riffing off of @James example p <- qplot(hp,wt,data=mtcars) + stat_smooth() You can use the intermediate stages of the ggplot building process to pull out the plotted data. The results of ggplot_build is a list, one component of which is data which is a list of dataframes which contain the computed values to be plotted. In … Read more

stat() error ‘No such file or directory’ when file name is returned by readdir()

dirp->d_name is the name of the file in the directory: for example, “udpclient.c”. The full name of the file is thus “/home/eipe/c/udpclient.c” – but your current working directory is /home/eipe, so stat() is trying to access “/home/eipe/udpclient.c”, which doesn’t exist. You can either change your working directory to argv[1] using chdir(), or you can prepend … Read more

How to get summary statistics by group

1. tapply I’ll put in my two cents for tapply(). tapply(df$dt, df$group, summary) You could write a custom function with the specific statistics you want or format the results: tapply(df$dt, df$group, function(x) format(summary(x), scientific = TRUE)) $A Min. 1st Qu. Median Mean 3rd Qu. Max. “5.900e+01” “5.975e+01” “6.100e+01” “6.100e+01” “6.225e+01” “6.300e+01” $B Min. 1st Qu. … Read more