How to perform two-sample t-tests in R by inputting sample statistics rather than the raw data? Let's say we have the statistics given below
gender mean sd n
f 1.666667 0.5773503 3
m 4.500000 0.5773503 4

How do you perform a two-sample t-test (to see if there is a significant difference between the means of men and women in some variable) using statistics like this rather than actual data?
I couldn't find anywhere on the internet how to do this. Most of the tutorials and even the manual deal with the test with the actual data set only.
 A: You can do the calculations based on the formula in the book (on the web page), or you can generate random data that has the properties stated (see the mvrnorm function in the MASS package) and use the regular t.test function on the simulated data.
A: You can write your own function based on what we know about the mechanics of the two-sample $t$-test. For example, this will do the job:
# m1, m2: the sample means
# s1, s2: the sample standard deviations
# n1, n2: the same sizes
# m0: the null value for the difference in means to be tested for. Default is 0. 
# equal.variance: whether or not to assume equal variance. Default is FALSE. 
t.test2 <- function(m1,m2,s1,s2,n1,n2,m0=0,equal.variance=FALSE)
{
    if( equal.variance==FALSE ) 
    {
        se <- sqrt( (s1^2/n1) + (s2^2/n2) )
        # welch-satterthwaite df
        df <- ( (s1^2/n1 + s2^2/n2)^2 )/( (s1^2/n1)^2/(n1-1) + (s2^2/n2)^2/(n2-1) )
    } else
    {
        # pooled standard deviation, scaled by the sample sizes
        se <- sqrt( (1/n1 + 1/n2) * ((n1-1)*s1^2 + (n2-1)*s2^2)/(n1+n2-2) ) 
        df <- n1+n2-2
    }      
    t <- (m1-m2-m0)/se 
    dat <- c(m1-m2, se, t, 2*pt(-abs(t),df))    
    names(dat) <- c("Difference of means", "Std Error", "t", "p-value")
    return(dat) 
}

Example usage:
set.seed(0)
x1 <- rnorm(100)
x2 <- rnorm(200) 
# you'll find this output agrees with that of t.test when you input x1,x2
(tt2 <- t.test2(mean(x1), mean(x2), sd(x1), sd(x2), length(x1), length(x2)))

Difference of means       Std Error               t         p-value 
         0.01183358      0.11348530      0.10427416      0.91704542 

This matches the result of t.test:
(tt <- t.test(x1, x2))

#         Welch Two Sample t-test
#   
#   data:  x1 and x2
#   t = 0.10427, df = 223.18, p-value = 0.917
#   alternative hypothesis: true difference in means is not equal to 0
#   95 percent confidence interval:
#    -0.2118062  0.2354734
#   sample estimates:
#    mean of x  mean of y 
#   0.02266845 0.01083487 

tt$statistic == tt2[["t"]]
#        t 
#     TRUE 

tt$p.value == tt2[["p-value"]]
# [1] TRUE

A: You just calculate it by hand:
$$
t = \frac{(\text{mean}_f - \text{mean}_m) - \text{expected difference}}{SE}  \\
~\\
~\\
SE = \sqrt{\frac{sd_f^2}{n_f} + \frac{sd_m^2}{n_m}}  \\
~\\
~\\
\text{where, }~~~df = n_m + n_f - 2
$$
The expected difference is probably zero.
If you want the p-value simply use the pt() function:
pt(t, df)

Thus, putting the code together:
> p = pt((((1.666667 - 4.500000) - 0)/sqrt(0.5773503/3 + 0.5773503/4)), (3 + 4 - 2))
> p
[1] 0.002272053

This assumes equal variances which is obvious because they have the same standard deviation.
A: The question asks about R, but the issue can arise with any other statistical software. Stata for example has various so-called immediate commands, which allow calculations from summary statistics alone. See http://www.stata.com/manuals13/rttest.pdf for the particular case of the ttesti command, which applies here. 
A: Another possible solution is to simulate the datasets and then use the standard t test function. It may be less efficient, computationally speaking, but it is very simple.
t.test.from.summary.data <- function(mean1, sd1, n1, mean2, sd2, n2, ...) {
    data1 <- scale(1:n1)*sd1 + mean1
    data2 <- scale(1:n2)*sd2 + mean2
    t.test(data1, data2, ...)
}

Given that the t test depends only on the sample summary statistics but disregards the actual sample distributions, this function will give exactly the same results (except for variable names) as the t test function:
x <- c(1.0, 1.2, 2.3, 4.2, 2.1, 3.0, 1.9, 2.0, 3.2, 1.6)
y <- c(3.5, 4.2, 3.3, 2.0, 1.7, 4.5, 2.7, 2.8, 3.3)
m_x <- mean(x)
m_y <- mean(y)
s_x <- sd(x)
s_y <- sd(y)
t.test.from.summary.data(m_x, s_x, 10, m_y, s_y, 9)

    Welch Two Sample t-test

data:  data1 and data2
t = -1.9755, df = 16.944, p-value = 0.06474
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -1.78101782  0.05879559
sample estimates:
mean of x mean of y 
 2.250000  3.111111 

t.test(x,y)

    Welch Two Sample t-test

data:  x and y
t = -1.9755, df = 16.944, p-value = 0.06474
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -1.78101782  0.05879559
sample estimates:
mean of x mean of y 
 2.250000  3.111111

