Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-Tarea1-CML-preg4 #7

Open
AlejandraLLI opened this issue Oct 20, 2019 · 1 comment
Open

issue-Tarea1-CML-preg4 #7

AlejandraLLI opened this issue Oct 20, 2019 · 1 comment

Comments

@AlejandraLLI
Copy link

AlejandraLLI commented Oct 20, 2019

Hola Adolfo,

En la pregunta 4, el código base en el archivo ufo-analysis.sh no devuelve un dataframe. El problema es que no se están eliminando correctamente los códigos html, i.e. el texto entre los signos <>. También se debe eliminar el salto de línea marcado como "^M" (o bien, \r) y agregar saltos de línea para que sea un data fame. Yo lo resolví de esta manera, pero tal vez se pueda hacer de forma más sencilla:

unction extract_table() {
# get table
sed -n '/<TABLE .>/,/</TABLE>/p' $1 |
# Fill missings with NA's
sed 's/<[BR]>/NA/g' |
# Remove HTML code
sed 's/<[^>]
>//g' |
# Remove ^M delimiters
sed 's/\r//g' |
# Remove empty lines
awk '/.+/ {print $0}' |
# Add pipes to lines that should be the end of lines
awk '{if (NR %7 == 0) {print $0"|"} else {print $0}}' |
# Paste all lines together in one line with tabs as separator
sed -e :a -e '$!N; s/\n/\t/; ta' |
# Separate lines using the added pipe
sed 's/|/\n/g' |
# Remove tabs at the begining of the lines
sed 's/^\t//g' |
# Remove emplty lines.
awk '/.+/ {print $0}'
}

Faltaría eliminar los encabezados duplicados en la parte de limpieza.

Adicionalmente, en la función calculate_stats se pide sacar conteos por color pero ésta no es una variable de los datos. ¿Lo cambiamos por ciudad?

¡Gracias!

@AlejandraLLI
Copy link
Author

El código anterior todavía tenía problemas con líneas que tenían información del tipo "< 5 minutes". El siguiente código ya soluciona esto.
function extract_table() {
# get table
sed -n '/<TABLE .>/,/</TABLE>/p' $1 |
# Fill non-responses with NA's
sed 's/
/NA/g' |
# Remove double NA's
sed 's/NANA//g' |
# Remove HTML code
sed 's/<[^<>]
>//g' |
# Remove ^M delimiters
sed 's/\r//g' |
# Remove empty lines
awk '/.+/ {print $0}' |
# Remove tabs
sed 's/\t/ /g' |
# Remove pipes
sed 's/|/ /g' |
# Add pipes to lines that should be the end of lines
awk '{if (NR %7 == 0) {print $0"|"} else {print $0}}' |
# Paste all lines together in one line with tabs as separator
sed -e :a -e '$!N; s/\n/\t/; ta' |
# Separate lines using the added pipe
sed 's/|/\n/g' |
# Remove tabs at the begining of the lines
sed 's/^\t//g' |
# Remove emplty lines.
awk '/.+/ {print $0}'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant