Perform a filter and save in csv

4

I would like to perform a filter in R. I have a database with 5 variables and more than 5000 rows. One of my variables is "room", in which I have 29 room (ex: room 1, room 2 ...).

I would like to perform a filter, to filter all the information it contains in my database for a certain room, and then export that information into a csv file.

I made a program, but it is not stored right in a csv file. I would like someone to give me a tip to better my code and / or help me solve this storage problem. Below is my code.

dados=read.csv("C:/teste/dados.csv", sep=";",header=TRUE) 
nome=dados$nome
perfil=dados$perfil
sala=dados$sala
forum=dados$forum
mensagem=dados$mensagem
BD=data.frame(nome,perfil,sala,forum,mensagem)
x2=subset(nome,sala=="(T2/14/EI) D01 - Diversidade e Cultura Inclusiva")
x3=subset(perfil,sala=="(T2/14/EI) D01 - Diversidade e Cultura Inclusiva")
x6=subset(sala,sala=="(T2/14/EI) D01 - Diversidade e Cultura Inclusiva")
x7=subset(forum,sala=="(T2/14/EI) D01 - Diversidade e Cultura Inclusiva")
x10=subset(mensagem,sala=="(T2/14/EI) D01 - Diversidade e Cultura Inclusiva")
dados1=paste(x2,x3,x6,x7,x10,sep=";")
cat("nome;perfil;sala;forum;mensagem", dados1, file="arquivo.csv", sep="\n",header=T)
    
asked by anonymous 13.04.2015 / 17:22

1 answer

4

To save in Brazilian CSV to use write.csv2() (and to read, read.csv2() ). What's more, you can use subset() in a data.frame, it greatly simplifies your code:

dados <- read.csv2("C:/teste/dados.csv", header=TRUE)
write.csv2(subset(dados, sala == "(T2/14/EI) D01 - Diversidade e Cultura Inclusiva"), "arquivo.csv",  row.names = FALSE)

The parameter row.names = FALSE is used to take the column with the line number (I personally think it only gets in the way)

    
13.04.2015 / 22:25