Skip to content

Instantly share code, notes, and snippets.

@eduardoklosowski
Last active November 29, 2017 13:45
Show Gist options
  • Save eduardoklosowski/27ebf3a97e2bc6f652eb8346ecb2071e to your computer and use it in GitHub Desktop.
Save eduardoklosowski/27ebf3a97e2bc6f652eb8346ecb2071e to your computer and use it in GitHub Desktop.
Processamento de tabela em R
x y
20 1.79
41.5 3.49
100 5.99
110 4.99
dados <- read.csv('dados.csv')
dados$xy <- dados$x * dados$y
dados$x2 <- dados$x ^ 2
dados$y2 <- dados$y ^ 2
ret <- dados
ret <- rbind(ret, data.frame(x=sum(dados$x), y=sum(dados$y), xy=sum(dados$xy), x2=sum(dados$x2), y2=sum(dados$y2)))
ret <- rbind(ret, data.frame(x=mean(dados$x), y=mean(dados$y), xy=mean(dados$xy), x2=mean(dados$x2), y2=mean(dados$y2)))
z <- lm(dados$y ~ dados$x)
summary(z)
write.csv(ret, file='ret.csv', row.names=FALSE)
plot(dados$y ~ dados$x, type='p', xlab='Peso (g)', ylab='Preço (R$)')
abline(z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment