1

Download the 1 km² attribute for the German Census 2011 immigrant rate, which has the German name Auslaender_A. Then, download the data for the vacancy rate (German name: Leerstandsquote) using the same raster resolution. Make sure to properly define missing values.
The function for downloading is z11::z11_get_1km_attribute(), and the one for listing all attributes of this size is z11::z11_list_1km_attributes(). There, you can also see both of the layer names.

2

Crop both datasets to the extent of Berlin (or any other big German city if you want to).
You can use the osmdata:getbb() function and the argument format_out = "sf_polygon" to receive a proper polygon for this purpose. Make sure only to extract the multipolygon and convert it to EPSG:3035.

3

That’s an open exercise: How would you try to conduct a basic correlational analysis of both raster data attributes?
You can coerce the whole raster data into a matrix using terra::as.matrix(x)